【问题标题】:How to change the colour of the statusbar in android?如何更改android中状态栏的颜色?
【发布时间】:2016-07-06 00:52:09
【问题描述】:

这是我的风格

 <style name="NoActionbar" parent="android:style/Theme.NoTitleBar">

    <item name="android:statusBarColor">#1c465d</item>

</style

>

我想通过删除操作栏来更改启动画面 但我意识到默认状态栏颜色是黑色,我无法将状态栏的颜色更改为绿色

为什么是这个节目?

我该怎么做?

【问题讨论】:

  • getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.hdr_bar));
  • 参考此链接here。祝你好运,希望这会有所帮助。
  • 为什么不将启动画面设置为全屏活动?
  • 也可以使用代码stackoverflow.com/a/30023811/3790150进行设置

标签: android styles android-manifest statusbar


【解决方案1】:

如上所述,将您的样式中的 colorPrimaryDark 属性设置为您喜欢的任何值。

<resources>
  <!-- inherit from the material theme -->
  <style name="AppTheme" parent="android:Theme.Material">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>

http://developer.android.com/training/material/theme.html

要正确地做到这一点,你应该在 color.xml 中声明你的颜色值,然后从样式中引用它。

【讨论】:

    【解决方案2】:

    你可以通过定义colorPrimaryDark项来设置状态栏颜色:

    <item name="colorPrimaryDark">#1c465d</item>
    

    【讨论】:

      【解决方案3】:

      转到 ~values/color.xml 并替换 colorPrimaryDark

      <item name="colorPrimaryDark">#1c465d</item>
      

      【讨论】:

        【解决方案4】:

        这样您可以通过编程方式设置状态栏颜色

        if (Build.VERSION.SDK_INT >= 21) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);         getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
        }
        

        【讨论】:

          猜你喜欢
          • 2014-04-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-09
          • 2016-09-08
          • 2020-03-07
          • 2015-04-13
          相关资源
          最近更新 更多