0

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

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

我打开应用程序后的那个

我打开应用程序之前的那个

一个的字体颜色是白色,而另一个是黑色。

4

3 回答 3

1

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

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

要使用材料设计,您的应用程序的 minSDK 必须为 21(棒棒糖),或者您可以使用 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

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

于 2015-10-08T06:55:14.333 回答
0

尝试这个。

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

于 2015-10-08T06:41:29.413 回答
0
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);
        }
于 2015-10-08T06:55:09.783 回答