The overlapping shadow effect remains in the navigation box NavigationView

I refined the Activity Drawer project template for Android Studio, which uses the Toolbar , v7.app.ActionBarDrawerToggle and NavigationView instead of the NavigationDrawerFragment (and layout / fragment_navigation_drawer.xml) file.

Navigation box in submersible sticky when the box is closed

It works great. Then I move on. I have a Navigation Box project in dive-sticky mode (full screen mode).

@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); } } @Override protected void onCreate(Bundle savedInstanceState) { ... toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = new ActionBarDrawerToggle( this, drawerLayout, R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; drawerLayout.setDrawerListener(drawerToggle); navigationView = (NavigationView) findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(this); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); drawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); drawerToggle.onConfigurationChanged(newConfig); } @Override public boolean onOptionsItemSelected(MenuItem item) { if (drawerToggle.onOptionsItemSelected(item)) { return true; } ... } 

There is a problem. The bars of the shadow overlay on the NavigationView that are displayed from the status bar (on the top side) and the navigation bar (on the bottom side) remain motionless.

When the navigation box is open

When the navigation box is open and sticky status is displayed and navigation bars are displayed

How can I get rid of them?

I reviewed the sources of v7.app.ActionBarDrawerToggle or Android NavigationView, but in vain.


Updated:

Thanks for the @lcw_gg advice, I completely got rid of the state shadow (as long as the shadows on the navigation bar remain). That is, set the android:windowFullscreen true attribute to the xml layout.

But I want to do this in Java code. I found a method and probably it is equivalent to the xml method:

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 

And at the same time, you no longer need to set these two flags - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN and View.SYSTEM_UI_FLAG_FULLSCREEN - on decorationView .

the shadow of the status bar disappeared and the navigation bar remained

However, I cannot find a way to get rid of the shadow of the navigation bar. I am waiting for a decision.

+8
android android-fullscreen navigation-drawer android-navigation-drawer android-navigationview
source share
2 answers

Finally, I did it.

The solution uses FLAG_LAYOUT_NO_LIMITS along with FLAG_FULLSCREEN in android.view.Window .

 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 

It got rid of both shadows perfectly.

enter image description here

lcw_gg comment was a very useful key to manipulating android.view.Window . Special thanks to him.

+13
source share

For those who have the same problem as above, but want to constantly show the system status bar (without using WindowManager.LayoutParams.FLAG_FULLSCREEN ), some additional work is necessary to prevent the content from alternating under the status bar on the candy. I did not notice the question about kitkat when I tested it.

I used two navigation boxes (left and right), and it was strange that only LEFT cast a shadow on the bottom. After applying WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS , as shown in the accepted answer, the shadow went away, but then there was a creep of the content in the status bar, as well as a drawing of the navigation box on top of the status bar; to the stop of the device.

To fix this, you should rewrite 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 below the status bar and also prevent the navigation box 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); } 
0
source share

All Articles