Android - How to change the status bar color of the NavigationView?

Viewed 1033

I've tried everything I can to achieve this feature but failed, "drawerLayout.setStatusBarBackground()" doesn't work, "android:windowTranslucentStatus:true" doen't work.

Here, first image is all I can do now, and the second one is the desired effect:

All I can do now

Desired effect

Thank you so much.

1 Answers

Problem is that NavigationView extends ScrimInsetsFrameLayout which listens window insets changes and adds dim line to the layout.

The sameScrimInsetsFrameLayout has styleable property insetForeground at least in com.google.android.material:material:1.1.0-alpha07

so if you use:

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

You only need to set that insetForeground to @color/transparent

For example:

<com.google.android.material.navigation.NavigationView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:insetForeground="@color/transparent"/>

Warning: This will not work if you set android:fitsSystemWindows="true".

Caution: Using this approach means that you have to manage your insets manually since you are using translucent status and not fitting system windws.

Related