如何禁用 Android LockScreen App 中的导航栏,例如 CM locker 和 OS8 锁屏
How to disable naviagation bar in Android LockScreen App like CM locker and OS8 lock screen
我尝试设置 systemUIView(View.GONE) 并使用沉浸式全屏模式。但用户始终可以通过触摸屏幕底部来恢复导航栏。我上面提到的应用程序无需root或设置默认启动器就可以隐藏它。
好吧,我从来没有做到这一点,但看来您需要设置一些其他标志才能获得这种视图:
When you use the SYSTEM_UI_FLAG_IMMERSIVE flag, it hides the system bars based on what other UI flags you have set (SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_FULLSCREEN, or both). When the user swipes inward in a system bars region, the system bars reappear and remain visible.
这是一个您可以用来设置这些标志的片段:
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
有关详细信息,请访问 android 开发者网站查看 Using Immersive Full-screen Mode。
希望对您有所帮助。
好的,我终于找到了解决方案,下面是解决方法:
使用SYSTEM_UI_FLAG_IMMERSIVE_STICKY
隐藏导航栏如下,你可以将代码放在activity
的onResume里面
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
然后,使用 WindowManger 添加系统错误 window 并将其覆盖在所有内容之上
您可以将这个不可避免的视图放在任何您喜欢的地方,但如果您想在用户锁定屏幕时进行此操作,请添加此标志:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Etvoilà
我尝试设置 systemUIView(View.GONE) 并使用沉浸式全屏模式。但用户始终可以通过触摸屏幕底部来恢复导航栏。我上面提到的应用程序无需root或设置默认启动器就可以隐藏它。
好吧,我从来没有做到这一点,但看来您需要设置一些其他标志才能获得这种视图:
When you use the SYSTEM_UI_FLAG_IMMERSIVE flag, it hides the system bars based on what other UI flags you have set (SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_FULLSCREEN, or both). When the user swipes inward in a system bars region, the system bars reappear and remain visible.
这是一个您可以用来设置这些标志的片段:
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.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);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
有关详细信息,请访问 android 开发者网站查看 Using Immersive Full-screen Mode。
希望对您有所帮助。
好的,我终于找到了解决方案,下面是解决方法:
使用
的onResume里面SYSTEM_UI_FLAG_IMMERSIVE_STICKY
隐藏导航栏如下,你可以将代码放在activityView decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; decorView.setSystemUiVisibility(uiOptions);
然后,使用 WindowManger 添加系统错误 window 并将其覆盖在所有内容之上
您可以将这个不可避免的视图放在任何您喜欢的地方,但如果您想在用户锁定屏幕时进行此操作,请添加此标志:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
Etvoilà