尝试自定义Widget.AppCompat.ActionBar时出错

时间:2015-01-19 22:15:13

标签: android android-actionbar android-appcompat

我刚刚更改为使用appcompat主题:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyTheme" parent="Theme.AppCompat">


        <item name="android:actionBarStyle">@style/MyActionBar</item>


    </style>
<style name="MyActionBar" parent="@android:style/Widget.AppCompat.ActionBar">
        <item name="android:backgroundStacked">@color/orange</item>
        <item name="android:background">@color/orange</item>

    </style>

我正在build.xml中导入AppCompat库

compile "com.android.support:appcompat-v7:21.+"

那么为什么会发生以下错误?

Error:Error retrieving parent for item: No resource found that matches the given name '@android:style/Widget.AppCompat.ActionBar'.

these docs看来它应该有效。

1 个答案:

答案 0 :(得分:1)

我发现在使用支持库时,应该省略android:前缀。所以试试吧:

Widget.AppCompat.ActionBar

修改

正如我所说,对于支持主题,您需要省略android:。这意味着无处不在:

<style name="MyTheme" parent="Theme.AppCompat">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
    <item name="backgroundStacked">@color/orange</item>
    <item name="background">@color/orange</item>
</style>

这一切都很好地指出了in the documentation