【问题标题】:How extend actionbar background to statusbar如何将操作栏背景扩展到状态栏
【发布时间】:2016-02-27 15:22:50
【问题描述】:

如何将AppBar背景扩展到状态栏?有可能吗?

【问题讨论】:

    标签: android android-layout android-statusbar


    【解决方案1】:

    在您的 onCreate(); 中调用它

    getWindow().getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    getWindow().setStatusBarColor(Color.TRANSPARENT);
    

    将您的视图布局设置为全屏并使状态栏颜色透明,适用于 Api21 及更高版本。

    【讨论】:

      【解决方案2】:

      编辑:我最初发布了一个基于外部链接的解决方案,但现在不起作用。这是代码:

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

      并将android:fitsSystemWindows 设置为true

      【讨论】:

        【解决方案3】:

        在API30之前,可以使用:

        1. 主题Theme.MaterialComponents.Light.NoActionBar
        2. 设置窗口标志:
                window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                )
        
        1. 使用android:fitsSystemWindows="true" 进行顶部布局

        我不知道 API30+ 的解决方案

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-31
          • 1970-01-01
          • 2012-03-06
          • 1970-01-01
          相关资源
          最近更新 更多