4

I want to use the AppTheme android:Theme.Material.Light.DarkActionBar for my app. This is available from SDK 21...My minimum SDK is 16. I have the support library com.android.support:appcompat-v7:22.0.0 in my build gradle file. I want to create a second styles file under the the values folder. I want to have two styles files...one for Lollipop...greyed out version 22 next to it...and one for pre Lollipop. How to do this?

4 Answers 4

7

As said create a values folder for a specific Api Level

res/values-v21/styles.xml
res/values/styles.xml

In values/styles.xml create to styles:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>
    <item name="colorAccent">@color/accentColor</item>
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style

<style name="AppTheme" parent="AppTheme.Base">
</style>

In values-v21/styles.xml create to styles:

<!-- Themes for Android API21 -->
<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:colorPrimary">@color/primaryColor</item>
    <item name="android:colorPrimaryDark">@color/primaryColorDark</item>
    <item name="android:colorAccent">@color/accentColor</item>
</style>

Inside your AndroidManifest.xml you should use AppTheme as your global application theme

Further you should use the Toolbar from the SupportLibary instead of the default Actionbar. This is why the Base Theme sets the Actionbar to false

3

As suggested in the other answers you can use different styles.xml file in different folders.

I would like to add an option to other answers.

You can define a Base Style used by each versions, and customize singles attributes.

In res/values/styles.xml

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>
    <item name="colorAccent">@color/accentColor</item>
</style>

<style name="AppTheme" parent="AppTheme.Base">
   <!-- custom pre-Lollipop attributes -->
</style>

In res/values-v21/styles.xml

<style name="AppTheme" parent="AppTheme.Base">
   <!-- custom Lollipop attributes -->
</style>

Finally use the AppTheme in your Activity (you have to use a ` ActionBarActivity).

2

You should add another folder called "values-v21" in your "res" directory. Then create a "styles.xml" within that directory for your Lollipop styles.

2

Create two styles.xml files in different folders, e.g:

res/values-v21/styles.xml
res/values/styles.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.