Ich habe seit Tagen damit gekämpft und habe noch keine Lösung gefunden. Ich habe eine NavigationDrawer-Aktivität mit einer Toolbar und mehreren Fragmenten, einfach so. Unerklärlicherweise bleibt die Toolbar hinter der Statusleiste ONLY auf Android 4.4 (API 19).Android Toolbar hinter Statusleiste auf API 19
habe ich alles fand ich verwendet habe ich den Code aus anderen Anwendungen auch kopiert, wo dies funktioniert, aber nichts geändert.
Dies ist um einen entsprechenden Code:
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "xxx"
minSdkVersion 16
targetSdkVersion 24
versionCode 3
versionName "1.0"
}
signingConfigs {
...
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
useProguard false
applicationIdSuffix ".debug"
}
}
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://clojars.org/repo/" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.crashlytics.sdk.android:crashlytics:[email protected]') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.google.android.gms:play-services-gcm:9.2.1'
compile 'com.google.android.gms:play-services-location:9.2.1'
compile 'com.google.android.gms:play-services-maps:9.2.1'
compile 'com.squareup:android-times-square:[email protected]'
compile 'frankiesardo:icepick:3.2.0'
provided 'frankiesardo:icepick-processor:3.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'net.danlew:android.joda:2.9.3'
compile 'com.github.JakeWharton:ViewPagerIndicator:[email protected]'
}
Android Manifest
<application
android:name=".MyApplication"
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/Base.AppTheme">
<activity
android:name=".activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Base.AppTheme.Main"
android:windowSoftInputMode="stateHidden"/>
</application>
themes.xml
<resources>
<!-- Base -->
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColor_dark</item>
<item name="colorAccent">@color/accentColor</item>
<item name="android:windowBackground">@color/background_activity</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:fontFamily">sans-serif</item>
</style>
<!-- Main Activity -->
<style name="Base.AppTheme.Main">
<item name="android:textColorSecondary">@android:color/white</item>
</style>
</resources>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_drawer_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/background_navigationDrawer"
android:fitsSystemWindows="true"
app:itemBackground="@drawable/drawer_item"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/activity_drawer_drawer">
<TextView
android:id="@+id/nav_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:padding="16dp"
android:textColor="@android:color/white"
tools:text="Version 0.0.0"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
app_bar_drawer_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity"
tools:showIn="@layout/activity_main">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/toolbar_title"
style="@style/TextView.Toolbar" />
<ImageView
android:id="@+id/toolbar_logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/content_desc_logo"
android:padding="12dp"
android:scaleType="fitCenter"
android:src="@drawable/logo_toolbar"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/toolbat_tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:visibility="gone" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<include layout="@layout/component_loading_spinner" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.MainActivity"
tools:showIn="@layout/app_bar_drawer_main" />
fragment_browser.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">
...
</LinearLayout>
</ScrollView/>
Was mache ich falsch ?? Was muss ich auf API 19 tun, damit fitSystemWindows
funktioniert, so dass Toolbar
unterhalb der Statusleiste angezeigt wird?