【问题标题】:How to hide navigation bar in Android App Code如何在 Android 应用代码中隐藏导航栏
【发布时间】:2017-04-28 18:25:03
【问题描述】:

我将此代码添加到我的应用程序中;

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

但是代码强制我将“SuppressLint NewApi 添加到 MainActivity”。还有一个关于“View.SYSTEM_UI_FLAG_FULLSCREEN”的错误。代码说“更改为....”所以我必须做什么我不知道。

请帮帮我。非常感谢。

【问题讨论】:

标签: android navigation hide tablet adk


【解决方案1】:

这是 在 Activity 中隐藏导航栏的简单代码。它正在工作。

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

【讨论】:

    【解决方案2】:

    对于 API 级别 19:

    除了设置全屏标志外,我还必须添加以下内容来隐藏软键:

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

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

    您还可以设置粘性沉浸,如下所述: https://developer.android.com/training/system-ui/immersive.html

    【讨论】:

      【解决方案3】:

      您使用的代码适用于 API 级别 14 或更高级别,如文档 here 中所述

      SuppressLint NewApi to MainActivity 发生的原因可能是您的目标 API 级别(或您的 minTarget)小于 14。

      正如post 所说,您无法隐藏导航栏

      编辑:

      设置您的android:minSdkVersion="14" 有一个限制:如果您使用的设备没有传统硬件键(返回、主页、菜单),则无法隐藏导航栏。

      【讨论】:

      • 我是android新手,怎么知道我的Api Level。我只知道我的设备版本是4.0.4
      • 打开您的AndroidManifest.xml 并在<uses-sdk> 标签中查看关于TargetVersion 的行。
      • 我正在更新我的答案,检查一下:)
      • 好的,我做到了,但我无法隐藏导航栏:/
      【解决方案4】:

      我就是这样做的 - 隐藏标题并使其全屏显示:

      // requesting to turn the title OFF
              requestWindowFeature(Window.FEATURE_NO_TITLE);
              // making it full screen
              getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      

      我的 AndroidManifest 中的 Application 下也有这个:

      android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
      

      我应该注意到这是 13 的 minSDK 版本和 19 (4.4 KitKat) 的目标

      【讨论】:

        【解决方案5】:

        我是一个非常新手的开发人员,但我发现我的解决方案是更改主题并将我的主题基于任何“...NoActionBar”主题。 我还没有弄清楚如何构建主题或修改样式,但我认为这可能是摆脱顶部操作栏的最有效方法。 它不会让你进入全屏模式。那,我相信你必须以编程方式进行。

        <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="android:windowNoTitle">true</item>
        </style>
        <resources/>
        

        另外,如果您想了解更多关于主题的信息,这似乎是个不错的地方:https://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-23
          • 1970-01-01
          相关资源
          最近更新 更多