Search code examples
androidandroid-5.0-lollipop

Converting my Application Theme to Lollipop


I am currently working on some changes to my app to properly target the new Android 5.0 Lollipop that has just been released.

I have the following in my styles.xml files in the values-v21 directory

<resources>

    <!-- Application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:actionBarTabTextStyle">@style/actionBarTabStyle</item>
        <item name="android:actionMenuTextColor">@color/white</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/appPrimaryColour</item>
    </style>

    <style name="actionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabText">
        <item name="android:textColor">@color/white</item>
    </style>

</resources>

I've changed the theme but I have customised my action bar with the following for the old Holo theme

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">

and

<style name="actionBarTabStyle" parent="@android:style/Widget.Holo.ActionBar.TabText">

I can't find what the equivalent would be for Lollipop, I've tried @android:style/Widget.Material.Light.ActionBar.Solid.Inverse @android:style/Widget.Material.ActionBar.TabText" but it then says it can't find the resources.


Solution

  • Just extend from Theme.Material.Light.DarkActionBar, which sets up the action bar theme to point to Theme.Material (dark) values for background and foreground colors. Also, you should be setting colorPrimary, colorPrimaryDark, and colorAccent in your AppTheme rather than manually setting the action bar background color.

    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <item name="android:colorPrimary">@color/appPrimaryColour</item>
        <item name="android:colorPrimaryDark"> ... </item>
        <item name="android:colorAccent"> ... </item>
    </style>