这个问题已经被问过很多次了:
如何在安卓上永久隐藏状态栏?
安卓ICS隐藏系统栏
隐藏安卓永久系统栏
但大多数情况下,答案不起作用,或者只能在用户用手指滑动之前隐藏。
这会导致应用程序崩溃。
这将它暂时隐藏起来。
设置systemUIVisiblity具有完全相同的效果。
这似乎没有任何作用,但如果它有作用的话,它可能只会在滑动时隐藏。
我已经尝试在不同的事件上重复调用这些代码块:
创建一个TextView并在点击时调用代码块。
这段代码摘自https://developer.android.com/training/system-ui/visibility:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
这会导致应用程序崩溃。
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
这将它暂时隐藏起来。
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
设置systemUIVisiblity具有完全相同的效果。
val windowInsetsController =
ViewCompat.getWindowInsetsController(window.decorView) ?: return
// Configure the behavior of the hidden system bars
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Hide both the status bar and the navigation bar
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
这似乎没有任何作用,但如果它有作用的话,它可能只会在滑动时隐藏。
我已经尝试在不同的事件上重复调用这些代码块:
val screenText : TextView = findViewById(R.id.textView5);
screenText.setOnClickListener {
hideSystemUI()
}
创建一个TextView并在点击时调用代码块。
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
hideSystemUI()
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
这段代码摘自https://developer.android.com/training/system-ui/visibility:
但它们的实现方法有些hacky,如果你很快就可以展开状态栏。导航栏在滑动后总是会出现。
为什么我想让这些栏消失呢? 因为我正在编写一个启动器。它应该类似于三星儿童模式。在输入密码之前,用户应该被禁止更改系统设置中的任何内容。如何在这些限制下实现呢?