简体   繁体   English

如何在Android中更改通知栏的背景颜色,即“元素颜色和文本颜色”?

[英]How to change the background color i.e. “element color and text color” of notification bar in Android…?

Please help... 请帮忙...

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: 我必须更改状态栏的元素颜色和文本颜色,还必须更改Android中标题栏的文本颜色:

The existing code is as follows: 现有代码如下:

styles.xml 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 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 row_data.xml

Layout 布局

Please help..... 请帮忙.....

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. status_bar_color将是您的自定义颜色资源。

  2. android:windowLightStatusBar = true, status bar text color will be compatible (grey) when status bar color is light. android:windowLightStatusBar = true,状态栏颜色为浅色时,状态栏文本颜色为兼容(灰色)。

    android:windowLightStatusBar = false, status bar text color will be compatible (white) when status bar color is dark. android:windowLightStatusBar = false,状态栏颜色为暗时,状态栏文本颜色将兼容(白色)。

    ref is here 裁判在这里

  3. Tested in above api level 23 在api级别23以上测试

The action bar takes the colour for the titles and icons from textColorPrimary 操作栏从textColorPrimary获取标题和图标的颜色

However this will also affect the default text for edit texts and text views if you set it on the app theme. 但是,如果您在应用程序主题上进行设置,这也会影响编辑文本和文本视图的默认文本。

To get around this create a separate theme for the app bar that includes the text colour change and either reference it in the app theme as the app bar style or set it on the toolbar in the XML if you have a custom toolbar. 要解决此问题,请为应用程序栏创建一个单独的主题,其中包括文本颜色更改,然后在应用程序主题中将其引用为应用程序栏样式,或者在XML中的工具栏上进行设置(如果您有自定义工具栏)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM