Search code examples
androidnavigation-drawerandroid-design-libraryandroiddesignsupport

Navigation Drawer statusbar


I'm having trouble making Navigation drawer over statusbar.

I'm using new Design support library. In blogspot thay said:

NavigationView takes care of the scrim protection of the status bar for you, ensuring that your NavigationView interacts with the status bar appropriately on API21+ devices.

But it has no documentation so I'm very confused how to use Drawer to achieve desired effect.

I tried inserting following attributes in my styles-v21:

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

after this Navigation drawer is working as needed but, other activities have transparent statusbar.

Can somebody give me a better solution?


Solution

  • The best solution here is to create special theme for activity with navigation like this.

    in styles.xml

    <style name="NavigationDrawerTheme" parent="AppTheme"/>
    

    but in styles v21 you will override this as

    <style name="NavigationDrawerTheme" parent="AppTheme">
            <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
    

    and in AndroidManifest.xml you will set

    <activity
        android:theme="@style/NavigationDrawerTheme"
        android:name=".activities.MainActivity"
        android:label="@string/title_activity_main" />
    

    So you will have correct behavior in all activities. :-)

    P.S If someone needs more explanation, comment.