以编程方式启用/禁用沉浸模式 [英] Programmatically enable/disable Immersive Mode
问题描述
我希望使我的Android应用全屏显示,但仅在特定屏幕(我的设置屏幕)上显示android导航栏.我知道将导航栏永久隐藏在屏幕上很危险,但是我想知道是否有可能.我已经研究过将设备植根并使用Xposed框架.
I'm looking to make my Android app fullscreen, but only showing the android navigation bar on a certain screen (my settings screen). I know that it is dangerous to hide the navigation bar permanently on a screen, but I want to know if this is possible. I have looked into rooting my device and using the Xposed framework.
是否可以通过编程方式禁用导航栏或粘滞模式",并在以后重新启用?
Is there a way to programmatically disable the navigation bar, or "sticky mode", and re-enable later?
我已经看过Android浸入模式,但是如果用户触摸边缘,导航栏似乎仍然会显示.我要删除导航栏的任何提示,直到它们转到我的设置屏幕为止.
I've looked at the Android Immersive Mode but it seems like the navigation bar will still show if the user touches the edge. I want to remove any hint of the navigation bar until they go to my settings screen.
推荐答案
是可以的.使用下面的代码片段实现所需的功能.
Yes it is possible. Use the below code snippet to achieve the desired functionality.
// 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.
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);
}
// 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() {
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);
}
有关更多详细信息,请参见下面的google文档:
For more details refer the the below google documentation :
https://developer.android.com/training/system-ui/immersive.html
要永久隐藏它,您可以尝试使用类似的方法(Hacky)
EDIT 1 : To hide it permanently may be you could try something like this (Hacky)
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
hideSystemUI();
}
});`
这篇关于以编程方式启用/禁用沉浸模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!