android: 如何修改状态栏的字体颜色

android: how to modify the font-color of status bar

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

下面两张图帮助描述 question.Thanks!

the one after I open the application

the one before I open the application

一个字体颜色是白色,一个是黑色

试试这个。

将此行放入 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/

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);
        }

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

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

要使用 material 设计您的应用程序的 minSDK 必须是 21 (Lollipop) 或者您可以使用以前版本的 v7 支持库。

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

现在,有多种方法可以设置状态栏的颜色。 首先,每次都通过 activity 动态更改为您想要的颜色(您必须向您的资源声明颜色 "blue") - 在您的内部 activity 类型:

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

第二个是通过您的资源扩展 material 设计 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

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