【问题标题】:Hide button bar in android在android中隐藏按钮栏
【发布时间】:2014-01-30 14:14:58
【问题描述】:

我正在开发一个需要全屏模式的应用程序。

我尝试在清单中使用此代码,

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

但什么也没发生,按钮栏(如主页、返回和最近的任务应用程序)仍然存在。我需要隐藏它们才能完全拥有全屏。请帮我解决一下这个。谢谢你。

【问题讨论】:

    标签: android


    【解决方案1】:
    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);
    

    developer docs

    从 API 19 以后,您可以使用SYSTEM_UI_FLAG_IMMERSIVE_STICKY 标志:

    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
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    decorView.setSystemUiVisibility(uiOptions);
    

    参见文档here

    【讨论】:

    • @androidBoomer 是的,通过这种方法,触摸屏幕上的任何位置都会导致导航栏(和状态栏)重新出现并保持可见。用户交互导致标志被清除。
    • 这是标准做法。用户交互将导致标志被清除以启用导航。
    • 那么我该怎么做才能使它成为不被清除的标志?
    • @androidBoomer 你不能,但你可以在一定时间后重置标志
    【解决方案2】:

    尝试在setContentView(R.layout.MainActivity);之前写这段代码

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    这段代码对我有用

    【讨论】:

    • 我不确定提问者是否想把时间栏等也隐藏起来。
    • 在我的代码中,带有时间的任务栏实际上是隐藏的。但是按钮栏不是...
    • 是的。它消失了,但底部的按钮没有。
    【解决方案3】:

    @bladefury 有一个很好的答案,但您可能也想研究一下...

    您还在 4.4 KitKat 中描述了一个名为 Immersive Mode 的新功能。 请注意,您需要 API 19 才能对此进行测试。

    查看developer documents

    【讨论】:

      【解决方案4】:

      经过大量研究,我终于弄明白了,并将我的活动设为全屏模式。

      getWindow().getDecorView().setSystemUiVisibility(8);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-11
        • 1970-01-01
        • 1970-01-01
        • 2013-08-30
        • 2019-07-02
        • 2010-11-22
        • 2012-04-21
        • 1970-01-01
        相关资源
        最近更新 更多