cw fei cw fei - 2 months ago 26
Android Question

Issue between android:windowLightStatusBar and Navigation Drawer

I have set

android:windowLightStatusBar
to
true
to display black icons and text on status bar inside my app as picture below.

enter image description here

However, the Navigation Drawer no longer fit to the screen, see the picture below. This is because to ensure
android:windowLightStatusBar
works,
android:windowTranslucentStatus
must be set to false. Any workaround? App like Google Calendar seem to work fine with this feature.

enter image description here

Here's my main activity's XML

<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:background="@color/colorToolbarBackground"
android:fitsSystemWindows="true"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/app_bar" />

<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>


<android.support.design.widget.NavigationView

android:id="@+id/navigation_view"
android:background="@color/colorWhite"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"

app:menu="@menu/navigation_view_items" />

</android.support.v4.widget.DrawerLayout>

Answer

Remove this line from layout.xml

android:fitsSystemWindows="true"

And add this to styles-v21.xml

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

in styles.xml

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

in Manifest.xml add this in your Activity Main

android:theme="@style/AppTheme.NoActionBar"

And wrap AppBarLayout tag into this:

<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=".MainActivity">

    <!-- Here AppBarLayout ecc -->

</android.support.design.widget.CoordinatorLayout>

<!-- Here NavigationView ecc -->

AppBarLayout must have

android:theme="@style/AppTheme.AppBarOverlay"
Comments