gpt4 book ai didi

android - 当我在 Android 中按下操作栏菜单时如何隐藏导航栏

转载 作者:行者123 更新时间:2023-11-30 02:07:19 25 4
gpt4 key购买 nike

我隐藏了导航栏(见下文),但是当我按下操作栏上的菜单按钮时,导航栏立即出现。我可以隐藏导航吗?永久禁止?

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

setContentView(R.layout.activity_fomenu);
}

最佳答案

看看 documentation .它说隐藏导航使用

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

您已经在这样做了。但是然后它说

With this approach, touching anywhere on the screen causes the navigation bar (and status bar) to reappear and remain visible. The user interaction causes the flags to be be cleared. Once the flags have been cleared, your app needs to reset them if you want to hide the bars again. See Responding to UI Visibility Changes for a discussion of how to listen for UI visibility changes so that your app can respond accordingly.

这意味着您必须在用户选择选项菜单时重置标志。还提供了示例代码 here .

关于android - 当我在 Android 中按下操作栏菜单时如何隐藏导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30488970/

25 4 0