[英]Completely hiding navigation bar (not only buttons) in android
I am using "Navigation Drawer Activity" template from latest Android Studio (2021.2.1 Patch 2) as a start.我正在使用来自最新 Android Studio(2021.2.1 补丁 2)的“导航抽屉活动”模板作为开始。
How can I hide navigation bar completely?如何完全隐藏导航栏? Following code only hides the buttons but navigation bar's white background still exists.以下代码仅隐藏按钮,但导航栏的白色背景仍然存在。
View decorView = getWindow().getDecorView();
int uiOptions = SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Thanks.谢谢。
Apply this code in onCreate()
of your activity:在活动的onCreate()
中应用此代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (window != null) {
window.decorView.windowInsetsController!!.hide(WindowInsets.Type.statusBars())
window.decorView.windowInsetsController!!.hide(
WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()
)
}
} else {
val decorView = window.decorView
val uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
decorView.systemUiVisibility = uiOptions
}
java version: java 版本:
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
getWindow().getInsetsController().hide(WindowInsetsCompat.Type.systemBars());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.