Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

java - How to change the background color i.e. "element color and text color" of notification bar in Android...?

I have to change the element color and text color of status bar and I also have to change the text color of title bar in Android:

The existing code is as follows:

styles.xml

<style name="AppThemeNew" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:statusBarColor">@color/status_bar_color</item>
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    </style>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#FDFEFE</color>
    <color name="colorPrimaryDark">#F4F6F6</color>
    <color name="colorAccent">#088da5</color>
    <color name="status_bar_color">#F4F6F6</color>
    <color name="status_bar_element_color">#AAB7B8</color>
</resources>

row_data.xml

Layout

Please help.....

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To change statusbar' element and text color, you could create custom theme like this:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:statusBarColor">@color/status_bar_color</item>
        <item name="android:windowLightStatusBar">false</item>
    </style>

Notes:

  1. status_bar_color would be your custom color resource.

  2. android:windowLightStatusBar = true, status bar text color will be compatible (grey) when status bar color is light.

    android:windowLightStatusBar = false, status bar text color will be compatible (white) when status bar color is dark.

    ref is here

  3. Tested in above api level 23


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...