使用appcompat v7的Android actionbar风格被后来的设备所忽略。

时间:2022-11-21 17:28:45

I am using the Action Bar support library (appcompat v7), my app is set to a minimum api of 7, and a target of 21.

我正在使用Action Bar支持库(appcompat v7),我的应用程序被设置为最小api 7,目标是21。

I have two styles files, a base one, and one targeted at devices api 11+.

我有两个样式文件,一个基础文件,一个针对设备api 11+。

When running the app on a device running KitKat, it seems that android:actionBarStyle is ignored, leaving the action bar styled as default (@style/Widget.AppCompat.ActionBar.Solid), instead of applying the given background.

在运行KitKat的设备上运行这个应用程序时,似乎忽略了android:actionBarStyle,将动作条设置为默认样式(@style/Widget.AppCompat.ActionBar.Solid),而不是应用给定的背景。

But if I remove my v11 styles/comment them out, KitKat listens to the actionBarStyle attribute set in the base styles.xml file and sets my custom background without any problems.

但是如果我删除了v11样式/注释掉它们,KitKat就会听基于基本样式的actionBarStyle属性。xml文件,并设置我的自定义背景,没有任何问题。

So my question, where am I going wrong with the v11 styles?

我的问题是,v11样式哪里出错了?

From what I understand, according to the android docs, you are supposed to supply the additional styles for devices running 11+ using the android: prefix, but this just doesn't seem to be working for me.

据我所知,根据android文档,你应该为运行11+的设备提供额外的样式,使用android:前缀,但这似乎并不适合我。

Stripped down, this is my /res/values/styles.xml file:

这是我的/res/值/样式。xml文件:

<style name="My.Theme" parent="@style/Theme.AppCompat">
    <item name="actionBarStyle">@style/ActionBar.Solid</item>
</style>

<style name="ActionBar.Solid" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="background">@drawable/ab_solid_</item>
</style>

and this is my /res/values-v11/styles.xml file:

这是我的/res/values-v11/styles。xml文件:

<style name="My.Theme" parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/ActionBar.Solid</item>
</style>

<style name="ActionBar.Solid" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="android:background">@drawable/ab_solid_</item>
</style>

as you can see, the only difference between the two is the use of the android: prefix.

如您所见,两者之间的惟一区别是使用android:前缀。

1 个解决方案

#1


4  

According to the official doc, with the new AppCompat-v21, you can remove all of values-v14+ Action Bar styles and use only one theme declaration, in values:

根据官方文档,通过新的AppCompat-v21,您可以删除所有的value -v14+动作条样式,并且只使用一个主题声明,其值为:

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- Set AppCompat’s actionBarStyle -->
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>

#1


4  

According to the official doc, with the new AppCompat-v21, you can remove all of values-v14+ Action Bar styles and use only one theme declaration, in values:

根据官方文档,通过新的AppCompat-v21,您可以删除所有的value -v14+动作条样式,并且只使用一个主题声明,其值为:

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- Set AppCompat’s actionBarStyle -->
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>