Android actionbar style ignored by later devices, using appcompat v7

允我心安 提交于 2019-11-27 08:33:55

问题


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.

I have two styles files, a base one, and one targeted at devices 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.

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.

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

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.

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

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

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


回答1:


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>


来源:https://stackoverflow.com/questions/26810059/android-actionbar-style-ignored-by-later-devices-using-appcompat-v7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!