I am using "Navigation Drawer Activity" template from latest Android Studio (2021.2.1 Patch 2) as a start.
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:
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:
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
getWindow().getInsetsController().hide(WindowInsetsCompat.Type.systemBars());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.