问题描述
我已经完善了Android Studio的导航抽屉活动"项目模板,该模板使用工具栏, v7.app.ActionBarDrawerToggle 和 NavigationView NavigationDrawerFragment(和layout/fragment_navigation_drawer.xml).
I have refined the Navigation Drawer Activity project template of Android Studio, which uses Toolbar, v7.app.ActionBarDrawerToggle and NavigationView instead of the NavigationDrawerFragment (and layout/fragment_navigation_drawer.xml).
这是完美的工作.然后,我走得更远.我的导航抽屉项目处于沉浸式粘性(全屏)模式.
It is perfectly working. Then, I go further. I have my Navigation Drawer project in immersive-sticky (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;
}
...
}
问题出现了.从状态栏(在顶部)和导航栏(在底部)派生的NavigationView上重叠的阴影效果带保持不变.
A problem has risen. The bands of overlapped shadow effect on the NavigationView which are derived from status bar (on the top side) and navigation bar (on the bottom side) remain still.
我如何摆脱它们?
我查看了v7.app.ActionBarDrawerToggle或Android的NavigationView的资源,但徒劳无功.
I reviewed sources of v7.app.ActionBarDrawerToggle or NavigationView of Android, but in vain.
感谢@lcw_gg的建议,我完全摆脱了状态栏的阴影(同时保留了导航栏的阴影).那就是在布局xml中设置android:windowFullscreen
属性true
.
Thanks for @lcw_gg's advice, I have gotten rid of the status bar's shadow completely (while the navigation bar's shadow remains). That is to set android:windowFullscreen
attribute true
in layout xml.
但是我想用Java代码做到这一点.我找到了一种方法,它大概等同于xml方法:
But I want to do this in Java code. I found a way and probably it is equivalent to the xml way:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
并且这样做,您无需再将这两个标志-View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
和View.SYSTEM_UI_FLAG_FULLSCREEN
-设置为decorationView
.
And with doing this, you don't need any more to set these two flags -- View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
and View.SYSTEM_UI_FLAG_FULLSCREEN
-- to the decorationView
.
不过,我仍然找不到摆脱导航栏阴影的方法.我正在等待解决方案.
Still, I can't find the way to get rid of the navigation bar's shadow. I'm waiting for a solution.
推荐答案
最后,我做到了.
该解决方案将 FLAG_LAYOUT_NO_LIMITS
与 FLAG_FULLSCREEN
一起用于 android.view.Window
对象.
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的注释对于处理 android.view.Window
很有帮助.一个>.特别感谢他.
这篇关于重叠阴影效果保留在导航抽屉的NavigationView上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!