Development issue/problem:

I am trying to create a navigation drawer from the hardware specifications (as in a new gmail application). Notice how the content of the navigation panel is drawn behind the status bar:

Thanks to Chris Baines’ answer to this question, I was able to successfully move the navigation field behind the status bar in my application; it works very well. What doesn’t work is drawing the contents of the navigation box behind the status bar. I want the blue image of my box to appear behind the status bar, but this area is drawn in the color of the status bar, as shown in this screenshot.

How do I get the navigation box drawn in the area behind the status bar? I have published the relevant parts of my project below.

Basic Layout Containing a Navigation Field :

The theme of my activities

In onCreate() of my company, I do the following:

mDrawerLayout.setStatusBarBackground(R.color.primary_dark) ;

How can I solve this problem?

Solution 1:

For API 21+

For API 19+

Your layout should have android:fitsSystemWindows=false (default).

If you now want to change the translucency, you can do so per program:

Window = getWindow() ;

// Enable Status Bar Transparency (API 19 required)
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) ;

// Disable transparency of status strings (API 19 required)
window.getAttributes().flags &= (~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) ;

// set color (API 21 required)
window.setStatusBarColor(Color.RED) ;

I’ll leave it to you to look at all the versions of sdk.

Make navigation drawer draw behind status bar –

Solution 2:

values/themes.xml

values-v19/themes.xml

If you want to change the color (other than transparent black) of the status bar, you need to take a different approach with a custom view, because mDrawerLayout.setStatusBarBackgroundColor(int) is only enabled if this DrawerLayout matches SystemWindows (android:fitsSystemWindows=true), and if it does, it is drawn below the status bar, not behind it.

Solution 3:

I found a better way to do this on Android 5.0. The important thing is to use ScrimInsetFrameLayout as the base element of the navigation box (second view in DrawerLayout). This requires expanding the content to fill the space behind the status bar. You can set the following attribute in ScrimInsetFrameLayout to color the insertion correctly:

application: deploymentForeground=#4000

Also make sure that android:fitsSystemWindows=true is configured for the grid layout!

The source code for ScrimInsetFrameLayout can be found here: https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/ScrimInsetsFrameLayout.java.

Solution 4:

For those who struggle with a semi-transparent status bar combined with the nav bar, but don’t want to change.

 fitssystemwindowsnavigation drawer over status bar androidnavigation drawer over action bar androidandroid show content behind status barsetonapplywindowinsetslistener"setdecorfitssystemwindows"fitssystemwindows not working in fragmentandroid navigation drawer above status barhide status bar android – stack overflowhide status bar and toolbar androidhow to hide systembar in androidhide action bar androidsystemuivisibility deprecatedhow to remove title bar in android studionavigation drawer in android mediumnavigation drawer alternativereact-navigation drawer status barnavigationcontainer status barreact native status barreact native drawernavigation drawer on top of status bar androidnavigation drawer status bar androidfitssystemwindows not workingdrawerlayout status bar color

You May Also Like

8 Brilliant Printing Ideas to Improve 3D Printing & Best 3D Printers in 2021

Printing services are essential for the home, school, any other institution including…

How To Download And Install Windows 10 From USB?

You want to install Windows 10 on your computer using a USB…

Apple Set to Unveil Arm-based MacBook Models in Big Event on November 10

Apple today announced the launch of the new 13-inch MacBook Air and…

Conversions & Customer Service At Its Best –

To support this free service, we receive affiliate commissions through a number…