我使用此代码隐藏导航栏。
public void hideNavigation() {
try {
View decorView = getWindow().getDecorView();
decorView.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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
if (Build.VERSION.SDK_INT > 21) {
registerSystemUiVisibility();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void registerSystemUiVisibility() {
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
hideNavigation();
}
}
});
}
但是当我显示对话框或显示集中编辑文本的键盘时,导航栏将再次出现。代码不起作用。你能帮我吗?我使用adjustresize,因为固定标题在键盘显示时不滚动。谢谢 当键盘显示时: enter image description here
隐藏键盘时: enter image description here
答案 0 :(得分:0)
解决方案:
只需在“活动”中使用此方法:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
View decorView = getWindow().getDecorView();
if (hasFocus) {
decorView.setSystemUiVisibility(5894);
}
}
希望它能起作用。