android - ColorPrimaryDark 不是状态栏颜色

标签 android android-toolbar android-appcompat android-styles android-statusbar

我在应用程序中有两个样式文件,它没有将 colorPrimaryDark 作为状态栏颜色。我正在检查 Nexus 6,但它无法正常工作。是我缺少的东西。

enter image description here

样式.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" 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="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>


    </style>


</resources>

样式.xml(v21)

<resources>

    <!-- Base application theme. -->
    <!--Application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <!--All customizations that are NOT specific to a particular API-level can go here. -->
    </style>


</resources>

Menifest - 在任何 Activity 中都没有定义主题

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

颜色文件

<color name="colorPrimary">#35734F</color>
    <color name="colorPrimaryDark">#35734F</color>
    <color name="colorAccent">#D2AB67</color>

最佳答案

尝试添加 <item name="android:windowDrawsSystemBarBackgrounds">true</item><item name="android:statusBarColor">@android:color/transparent</item>在你的style.xml(v21) .

style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme" parent="AppBaseTheme">

</resources>

style.xml(v21)

<resources>

    <!-- Base application theme. -->
    <!--Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

</resources>

关于android - ColorPrimaryDark 不是状态栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43732440/

相关文章:

android - php 网站到 android 应用程序

Android:工具栏高度/阴影

android - 如何更改android中操作栏标题的字体

Android 支持库 23.2.0 导致工具栏箭头为黑色

android - Material Design 和 appcompat 不适用于较旧的 API 版本

java - Android Studio中的Appcompat Activity 以及androidx gradle版本问题

android - AppCompatRadioButton setSupportButtonTintList 方法出错

android - 使用 PowerManager.WakeLock 延长屏幕唤醒持续时间

java - 无法在 onItemClickListener 中获取项目

android - 如何使用光标获取嵌入音频文件的封面艺术?