【问题标题】:android: how to modify the font-color of status barandroid:如何修改状态栏的字体颜色
【发布时间】:2015-10-08 06:25:44
【问题描述】:

如何修改状态栏的字体颜色? 我发现一些android应用可以修改状态栏的字体颜色,我不知道怎么做。

以下两张图片有助于描述问题。谢谢!

the one after I open the application

the one before I open the application

一种字体颜色为白色,另一种为黑色。

【问题讨论】:

标签: android android-statusbar


【解决方案1】:

感谢 Material Design 的发布,您可以更改状态栏的颜色。 首先,您必须通过清单告诉您的应用使用材料设计(您可以使用您选择的材料主题):

android:theme="@android:style/Theme.Material.Light"

要使用材料设计,您的应用的 minSDK 必须为 21(Lollipop),或者您可以使用 v7 支持库以获取以前的版本。

https://developer.android.com/tools/support-library/features.html#v7

现在,有一些方法可以设置状态栏的颜色。 首先,每次都使用您想要的颜色通过活动动态更改它(您必须将颜色声明为“蓝色”到您的资源) - 在您的活动类型中:

getWindow().setStatusBarColor(getResources().getColor(R.color.blue));

第二个是通过你的资源xml扩展材料设计:

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

<!--  USE THIS FOR STATUS BAR COLOR -->
<item name="android:statusBarColor">@color/blue</item>
</style>
</resources>

https://developer.android.com/training/material/theme.html#ColorPalette

如需快速测试,请使用选项一,希望对您有所帮助!

【讨论】:

    【解决方案2】:

    试试这个。

    将此行放入你的gradle依赖结构中。

    compile "com.android.support:appcompat-v7:21.0.+"
    

    在你的 values/themes.xml 中

    <style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
        <!-- Here we setting appcompat’s actionBarStyle -->
        <item name="actionBarStyle">@style/MyActionBarStyle</item>
    
        <!-- ...and here we setting appcompat’s color theming attrs -->
        <item name="colorPrimary">@color/my_awesome_red</item>
        <item name="colorPrimaryDark">@color/my_awesome_darker_red</item>
    
        <!-- The rest of your attributes -->
    </style>
    

    更多详情:-https://chris.banes.me/2014/10/17/appcompat-v21/

    【讨论】:

      【解决方案3】:
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                  Window window = getWindow();
                  window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                  window.setStatusBarColor(R.color.your_color);
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-01
        • 2014-12-17
        • 1970-01-01
        • 2016-07-06
        • 2014-04-07
        • 1970-01-01
        相关资源
        最近更新 更多