6
votes

I am trying to get the translucent navigation bar with fitsSystemWindows="true". It works fine in kitkat, the translucent navigation bar show the content using android:clipToPadding="false". But Lollipop navigation bar doesnt show the content.

Image: navigation drawer closed

This is the xml:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:clipToPadding="false"
tools:context=".MainActivity">

<!-- The main content view -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- Your main content -->

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="8dp"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <Button
        android:layout_marginTop="24dp"
        android:background="@color/md_red_500"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="800dp" />

</LinearLayout>

<!-- The navigation drawer -->
<com.videum.javier.myapplicationeliminmar.ScrimInsetsFrameLayout
    android:clipToPadding="false"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/scrimInsetsFrameLayout"
    android:layout_width="320dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    android:elevation="10dp"
    android:fitsSystemWindows="true"
    app:insetForeground="#4000">

    <!-- Your drawer content -->

    <Button
        android:layout_marginTop="24dp"
        android:background="@color/md_red_500"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="800dp" />

</com.videum.javier.myapplicationeliminmar.ScrimInsetsFrameLayout>

This is the style (same v19 and v21):

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/md_red_500</item>
    <item name="colorPrimaryDark">@color/md_red_700</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

The java file only has the toolbar support.

I need that fitsSystemWindows keeps true always.

The navigation drawer works fine in both versions. For example, if I add a button inside it: navigation drawer opened

2
Have you figured this out yet. If you have could you write an answer please?SARose

2 Answers

0
votes

You haven't specified in the theme, that you take responsibility of drawing behind the system bars:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
-1
votes

Don't set fitsSystemWindow="true" in your DrawerLayout. By default, System Window is the window under status bar and above navigation bar even if you set windosTransclucentStatus/Navigation="true", which may make you think "now the windows is fullscreen". If you fit this window, of course the content won't expand to fit the whole screen.