Question

I am defining action bar styles for an Android device running 4.4.2. I've tested the styles on a device running 4.3 and they work prefectly. The phone running KitKat however refuses to apply any of the rules defined by the style. I've defined the same theme in all three folders: values, values-11 and values-14.

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
    <!-- Setting values in the android namespace affects API levels 14+ -->
    <item name="android:actionBarStyle">@style/MyStyledActionBar</item>
</style>

<style name="MyStyledActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <!-- Setting values in the android namespace affects API levels 14+ -->
    <item name="android:background">@drawable/oc_actionbar_background</item>
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
    <item name="android:actionMenuTextAppearance">@style/MyActionBarMenuText</item>
    <item name="android:actionMenuTextColor">@style/MyActionBarMenuText</item>
    <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverFlow</item>
    <item name="android:displayOptions">showHome</item>
</style>

<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">#696969</item>
</style>

<style name="MyActionBarMenuText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
    <item name="android:textColor">#696969</item>
</style>

<style name="MyActionButtonOverFlow" parent="@style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
    <item name="android:src">@drawable/ic_action_search</item>
</style>

I've also added

android:theme="@style/AppTheme"

to the manifest application tag. But the styles are still not applied. I have however managed to change the action bar properties at runtime (changing the color), but that's not a desirable way of handling such problems.

If anyone could advise me on the matter, I would be most grateful.

Was it helpful?

Solution

To prevent these kind of issues, I like to use the following tool to generate the style for me: http://jgilfelt.github.io/android-actionbarstylegenerator/

Easy to use tool that generates the style just like I want it. Might help you too, since you avoid these issues. Just paste this in your project, and you're done.

Other tools can be found here: http://romannurik.github.io/AndroidAssetStudio/index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top