简体   繁体   English

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

[英]Error trying to customize Widget.AppCompat.ActionBar

I have just changed to using the appcompat theme: 我刚刚更改为使用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>

I am importing the AppCompat libs in build.xml 我正在build.xml中导入AppCompat库

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

So why is this error below happening? 那么为什么下面的错误会发生呢?

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

From these docs it appears it should work. 这些文档看来,它应该可以工作。

I found that when using support libraries one should ommit the android: prefix. 我发现使用支持库时应省略android:前缀。 So just try: 因此,只需尝试:

Widget.AppCompat.ActionBar

Edit: 编辑:

As I've said, for support themes you need to ommit android: . 就像我说过的那样,对于支持主题,您需要省略android: :。 That means everywhere: 这意味着到处都是:

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

This is all nicely pointed out in the documentation . 文档中很好地指出了这一点。

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

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