1

I want to use the "immersive mode" in my app. I am following the documentation and working properly:

 private View mDecorView;
...

     @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            if (hasFocus) {
                mDecorView.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
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            }
        }
...
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        mDecorView = getWindow().getDecorView();

    }

This enables immersive full-screen mode. My problem is that I want to use only FLAG_IMMERSIVE_STICKY, as the same result as the Trello app:

enter image description here

The bars are transparent and are always visible. I searched for information and different combinations, but I get the result I want. I appreciate any help.

Thank you!

4

3 回答 3

2

Trello 使用半透明条 [1],而不是沉浸式模式,具有自定义透明操作栏背景。

[1] https://developer.android.com/about/versions/android-4.4.html#TranslucentBars

于 2014-02-28T19:29:31.757 回答
1

该文档还指出,您必须在 onCreate 方法中为活动设置 UI 标志。- https://developer.android.com/training/system-ui/immersive.html

实现这两个方法,在onCreate方法中调用hideSystemUI

// 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.
    mDecorView.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() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

这应该隐藏状态栏和导航栏。文档指出这应该隐藏导航和状态栏。对我来说,它只是隐藏了状态栏。

我希望这有帮助。

于 2014-05-12T17:01:21.977 回答
0

您正在寻找的标志是:

  • WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
  • WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION

您还可以使用以下方式在主题中使用标志:

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

不幸的是,如果您的应用使用操作栏,它不会立即像 Trello 应用一样出现。您必须使用一些技巧/黑客来使它看起来像 Trello 应用程序。如果您的应用使用操作栏,您可以节省时间并改用此库*。不用说,这只适用于 API 19+。

*就我个人而言,我不赞成仅仅为了扩展操作栏颜色而使用透明系统栏。我认为只有在系统栏下方显示内容或有全屏活动时才应使用它。

于 2014-02-28T19:57:07.417 回答