Using different themes for different Android versions

January 18, 2013
By

In this article, we will develop an Android Application that demonstrates how to use different themes for different Android versions.

As shown in the screenshot section, the text “Hello world!” will be displayed in blue, green and red when this application is run API level less than 11, greater than or equal to 11 and greater than or equal to 14 respectivity.

This application is developed in Eclipse 4.2.1 with ADT plugin ( 21.0.0 ) and Android SDK ( 21.0.0 )


1. Create a new Android application project namely “ThemeCustomizationVersionSpecific”

Create new Android Application project namely "ThemeCustomizationVersionSpecific"

Figure 1 : Create new Android Application project namely "ThemeCustomizationVersionSpecific"


2. Configure the project

Configure the application project

Figure 2 : Configure the application project


3. Design application launcher icon

Design Application launcher icon

Figure 3 : Design Application launcher icon


4. Create a blank activity to define MainActivity class

Create a blank activity

Figure 4 : Create a blank activity


5. Enter MainActivity details

Enter Main Activity Details

Figure 5 : Enter Main Activity Details


6. Update the file res/values/styles.xml


<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <color name="red">#ff0000</color>
    <color name="green">#00ff00</color>
    <color name="blue">#0000ff</color>

    <style name="AppBaseTheme" parent="android:Theme.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:textColor">@color/blue</item>
    </style>
</resources>

Note : The theme “AppTheme” defined in this file is used for Android versions of API level less than 11


7. Update the file res/values-v11/styles.xml


<resources>

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:textColor">@color/green</item>
    </style>

</resources>

Note : The theme “AppTheme” defined in this file is used for Android versions of API level greater than or equal to 11


8. Update the file res/values-v14/styles.xml


<resources>
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:textColor">@color/red</item>
    </style>
</resources>

Note : The theme “AppTheme” defined in this file is used for Android versions of API level greater than or equal to 14


9. Screenshots of the application executing in different Android SDK Versions

Application in Android API Level 8 ( Froyo )

Figure 6 : Application in Android API Level 8 ( Froyo )

Screenshot of the application in Android API Level 11

Figure 7 : Screenshot of the application in Android API Level 11 ( HoneyComb)

Screenshot of the application in Android API Level 16 ( JellyBean )

Figure 8 : Screenshot of the application in Android API Level 16 ( JellyBean )


10. Download Source Code


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: ,

One Response to Using different themes for different Android versions

  1. Madhujit on December 3, 2015 at 3:07 am

    This topic is very useful for a beginner like me. Thank You!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner