Android actionbar 样式被后来的设备忽略,使用 appcompat v7 [英] Android actionbar style ignored by later devices, using appcompat v7
问题描述
我正在使用操作栏支持库 (appcompat v7),我的应用设置为最小 api 7,目标为 21.
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.
我有两个样式文件,一个是基础文件,另一个是针对设备 api 11+.
I have two styles files, a base one, and one targeted at devices api 11+.
在运行 KitKat 的设备上运行应用程序时,似乎忽略了 android:actionBarStyle
,将操作栏保留为默认样式(@style/Widget.AppCompat.ActionBar.Solid),而不是应用给定的背景.
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.
但是,如果我删除我的 v11 样式/将它们注释掉,KitKat 会侦听在基本 style.xml 文件中设置的 actionBarStyle
属性并毫无问题地设置我的自定义背景.
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 样式哪里出了问题?
据我所知,根据 android 文档,您应该使用 android:
前缀为运行 11+ 的设备提供其他样式,但这似乎不起作用对我来说.
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.
精简,这是我的/res/values/styles.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>
这是我的 /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>
如您所见,两者的唯一区别是使用了 android:
前缀.
as you can see, the only difference between the two is the use of the android:
prefix.
推荐答案
根据官方文档,使用新 AppCompat-v21,您可以删除所有values-v14+ Action Bar样式并仅使用一个主题声明,在 values
中:
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
:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s actionBarStyle -->
<item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>
这篇关于Android actionbar 样式被后来的设备忽略,使用 appcompat v7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!