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

标签 android android-actionbar hide navigationbar

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

@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/

相关文章:

java - ListView 和线程安全的自定义适配器

android - 通过主机名连接

android - 如何在android另一个 Activity 中的操作栏上显示后退按钮

android - 通过按钮从一个选项卡 View 移动到另一个选项卡单击 Android ActionBar

windows - 隐藏 Windows 应用程序的控制台

css - 无法在 jQuery Mobile 应用程序中隐藏/显示元素

java - 在 Kotlin 中定义 log TAG 常量的最佳方法是什么?

android - 在 Android Studio 3.1 中将问题从 Gradle 3 迁移到 4

android - 如何在 fragment 中使用 setSupportActionBar

python - 当我们打开子框架时如何隐藏主框架