gpt4 book ai didi

java - 以编程方式启用/禁用沉浸模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:38 26 4
gpt4 key购买 nike

我希望让我的 Android 应用全屏显示,但只在特定屏幕(我的设置屏幕)上显示 android 导航栏。我知道在屏幕上永久隐藏导航栏是危险的,但我想知道这是否可能。我已经研究过对我的设备进行生根并使用 Xposed 框架。

有没有办法以编程方式禁用导航栏或“粘滞模式”,并在以后重新启用?

编辑:我看过 Android 沉浸式模式,但如果用户触摸边缘,导航栏似乎仍会显示。我想删除导航栏的任何提示,直到它们转到我的设置屏幕。

最佳答案

是的,这是可能的。使用下面的代码 fragment 来实现所需的功能。

// 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);
}

For more details refer the the below google documentation :

https://developer.android.com/training/system-ui/immersive.html

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();


}
});`

关于java - 以编程方式启用/禁用沉浸模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com