1

How do I change the Status Bar Color of my app that I'm making in Android Studio so that it changes to a static color on Android Lollipop 5.0 or higher and doesn't crash on Mobile running lower version of Android OS.

4

3 回答 3

0

请将此添加到您的应用样式中

<item name="colorPrimary">>#FFFF00</item>

<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#000000</item>
于 2015-10-08T04:35:40.913 回答
0

尝试使用这个,这对我有用

//changing statusbar
if (android.os.Build.VERSION.SDK_INT >= 21){
                Window window = this.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(this.getResources().getColor(R.color.primary_dark));
            }

用于更改颜色 ActionBar :

 <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">#ffff00</item>
    </style>

并在应用程序标签中声明您的清单

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/MyActionBar" >

希望有帮助

于 2015-10-08T02:54:44.630 回答
0

您可以通过两种方式做到这一点,或者为您的主题添加属性,例如

样式.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">>#ED3B3B</item>

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#BE2F2F</item>

    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#4DB6AC</item>

    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight & colorSwitchThumbNormal. -->
</style>

并且您的 AndroidManifest 的应用程序标签必须具有带有 AppTheme 的主题属性

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"> // This

或者,如果您希望在稍后阶段动态更改状态栏颜色,例如单击按钮或完成图像加载后,您可以在 Java 类中使用

if (android.os.Build.VERSION.SDK_INT >= 21){
    Window window = activity.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.setStatusBarColor("your color"));
}
于 2015-10-08T03:04:22.480 回答