繁体   English   中英

使用Theme.AppCompat时操作栏颜色不会更改

[英]Action bar color does not change when using Theme.AppCompat

我要做的就是让操作栏和状态栏更改颜色以进行材质设计。 以下是我创建的主题:

 <!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="android:colorPrimary">#FF5722</item>
    <!--<item name="android:statusBarColor">#E64A19</item>-->

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


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

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

</style>

但是,运行时状态栏的颜色会很好地更改,但操作栏仍为黑色。 我知道对此可能有一个简单的答案,但是我想念的是什么?

该问题与建议的问题不重复。 请删除标志。

由于您使用的是AppCompat,因此应使用AppCompat属性,而不要使用Android系统属性。

更改

android:colorPrimary

colorPrimary

整个过程应如下所示:

<!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#FF5722</item>

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

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

colorPrimary删除android: colorPrimary appcompat-v7在其主题中未使用android:前缀,最后我检查了一下。

暂无
暂无

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

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