Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用Theme.AppCompat时,操作栏颜色不会更改_Android_Android Appcompat_Android Theme - Fatal编程技术网

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

Android 使用Theme.AppCompat时,操作栏颜色不会更改,android,android-appcompat,android-theme,Android,Android Appcompat,Android Theme,我所要做的就是让actionbar和status bar改变颜色以进行材质设计。以下是我创建的主题: <!-- Base application theme. --> <style name="AppTheme2" parent="Theme.AppCompat"> <!-- colorPrimary is used for the default action bar background --> <item name="androi

我所要做的就是让actionbar和status bar改变颜色以进行材质设计。以下是我创建的主题:

 <!-- 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>

#FF5722
#E64A19
#FF9800
但是,当运行状态栏时,颜色会变细,但操作栏仍为黑色。我知道可能有一个简单的答案,但我遗漏了什么


这一问题不是所建议问题的重复。请删除标志。

colorPrimary
删除
android:
appcompat-v7
在其主题中没有使用
android:
前缀,上次我检查过。

colorPrimary
中删除
android:
appcompat-v7
在其主题中没有使用
android:
前缀,上次我检查过。

既然您使用的是appcompat,那么您应该使用appcompat属性,而不是android系统属性

改变

android: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>

#FF5722
#E64A19
#FF9800

因为您使用的是AppCompat,所以应该使用AppCompat属性,而不是Android系统属性

改变

android: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>

#FF5722
#E64A19
#FF9800

尝试将父主题更改为
theme.AppCompat.Light.NoActionBar
的可能副本尝试将父主题更改为
theme.AppCompat.Light.NoActionBar
的可能副本