I have refined the Navigation Drawer Activity project template of Android Studio, which uses Toolbar, v7.app.ActionBarDrawerToggle and
The accept answer has a problem. Setting flags FLAG_FULL_SCREEN
and FLAG_LAYOUT_NO_LIMITS
will make the insets of the window to be 0 and content may lay behind the system UIs.
It will work because NavigationView
, which is a subclass of ScrimInsetsFrameLayout
, listen to onApplyWindowInsets
and View.setWillNotDraw
to true when window insets are all 0.
You just need to add to your NavigationView
this:
app:insetForeground="@null"
Thanks to hata i have succeed to completely hide system UI, by merging his original code:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
View decorationView = getWindow().getDecorView();
decorationView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
with the solution code added in onCreate
of my Activity before calling inflate
:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Apparently, the flag WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
was the missing piece to make the full screen work as expected on my device (API 21)
At last, I made it.
The solution is using FLAG_LAYOUT_NO_LIMITS
together with FLAG_FULLSCREEN
to the android.view.Window object.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
This has gotten rid of both of the shadows perfectly.
lcw_gg's comment was very useful clue to manipulating android.view.Window. Special thanks to him.
For those with the same issue as above, but want to keep the system status bar always showing (thus not using WindowManager.LayoutParams.FLAG_FULLSCREEN
), there is some additional work you have to do to prevent a weird content creep underneath the status bar on lollipop. I didn't notice the issue on kitkat when I tested it.
I was using two navigation drawers (left and right) and weirdly had only the LEFT one casting the shadow on the bottom. Once applying WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
as shown in the accepted answer, the shadow went away but then had the content creep under the status bar as well as the navigation drawer drawing on top of the status bar; all the way to the device bezel.
To fix that you must overwrite your theme in v21 styles.xml to include:
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:statusBarColor">@color/colorPrimaryDark</item>
This will move the content back below the status bar and also prevent the navigation drawer from drawing on top of the status bar.
In addition to the above entries in my v21 styles, my activity code looked like this:
// Fixes bottom navbar shadows from appearing on side navigation drawers
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
getWindow().setAttributes(attributes);
}