3

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.

Sam Chen
  • 7,597
  • 2
  • 40
  • 73
  • https://stackoverflow.com/questions/22192291/how-to-change-the-status-bar-color-in-android – Pankaj Kumar Dec 21 '18 at 20:03
  • Thanks for the reply, but I'm asking the Navigation Drawer Status Bar (when you slide out, the topmost bar), not the default Status Bar (although they are the same...but I want to change the color for certain part of it) – Sam Chen Dec 21 '18 at 20:31
  • Did you able to figure it out? All i know is that behavior is distinct to `NavigationView` if you use `FrameLayout` instead, you can achieve this effect using translucent status and `android:windowDrawsSystemBarBackgrounds` you have to handle insets manually tho. – Alpha Sep 17 '19 at 07:29

1 Answers1

6

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.

Alpha
  • 1,754
  • 3
  • 21
  • 39