Themes across Android versions

This article unveils the secret of having your app's theme look consistent with the rest of the device's UI across all Android versions.

I don't often post pieces of code, but I thought this was an interesting enough subject to warrant a post. It's not really code, though.

If you've built a few apps, you've probably run into some theming issues. How do you get your app to have the standard OS look-and-feel across the different Android versions?

It's not difficult, but to have it look good on all current Android versions does require us to build the application for Android 4.0 (API level 14). Luckily, due to the introduction of the DeviceDefault theme, we will not have to upgrade the API level again in the future when a new theme comes out - it will now look good automatically.

We still have to cover the Honeycomb (Holo) and pre-Honeycomb (Black) cases, though. We do so by creating a new theme, and having it choose between device defaults by using API selectors. We will define three themes, the standard theme, a NoTitleBar(/NoActionBar) theme, and a Fullscreen theme.

If you modify your app in the way described here, standard components used by your activities will always look consistent with the rest of the device. Prior to Ice Cream Sandwich, OEMs usually skinned by overwriting the default skins, while in Ice Cream Sandwich and newer OEMs will modify the DeviceDefault skin. Note that on this API level you can still choose to use the Holo theme - and that Holo theme will actually look the way Google designed it, not OEM-specific.

Step 1: Changing Android API level

In Eclipse, right click on your project and go to Properties. Select the Android section, put a mark next to "Android 4.0" and click Apply.

If "Android 4.0" is not listed, make sure you install the needed SDK parts (Eclipse: Windows -> Android SDK Manager).

Now, open AndroidManifest.xml and make sure your <uses-sdk android:minSdkVersion="x" /> is still set to the minimum Android version you wish to support.

Step 2: Pre-Honeycomb theme (Black)

On Pre-Honeycomb Android devices, we'll use the Black theme, which is standard on most devices. We do so by creating a file called styles.xml in the res/values folder:

Code
#
1
<?xml version="1.0" encoding="utf-8"?>
2
<resources>
3
    <style 
4
        name="Theme.Chainfire"
5
        parent="android:Theme.Black">
6
    </style>
7
    <style 
8
        name="Theme.Chainfire.NoTitleBar"
9
        parent="android:Theme.Black.NoTitleBar">
10
    </style>
11
    <style 
12
        name="Theme.Chainfire.Fullscreen"
13
        parent="android:Theme.Black.NoTitleBar.Fullscreen">
14
    </style>
15
</resources>    

Step 3: Honeycomb theme (Holo)

On Honeycomb we want to be using the Holo theme available since Android 3.0 (API level 11). To do this, again we create a styles.xml file, but this time in the res/values-v11 folder:

Code
#
1
<?xml version="1.0" encoding="utf-8"?>
2
<resources>
3
    <style 
4
        name="Theme.Chainfire"
5
        parent="android:Theme.Holo">
6
    </style>
7
    <style 
8
        name="Theme.Chainfire.NoTitleBar"
9
        parent="android:Theme.Holo.NoActionBar">
10
    </style>
11
    <style 
12
        name="Theme.Chainfire.Fullscreen"
13
        parent="android:Theme.Holo.NoActionBar.Fullscreen">
14
    </style>
15
</resources>    

You might need to create that res/values-v11 folder. The v11 part is called an API selector. The styles.xml file present in this folder will override the styles.xml file present in the res/values folder if-and-only-if the API level of the device is 11 or higher.

Step 4: Post-Honeycomb theme (DeviceDefault)

On Ice Cream Sandwich and beyond, we will want to use the DeviceDefault theme, introduced in Android 4.0 (API level 14). This will ensure your app will look consistent with the rest of the device's user interface. We could keep using Holo, but prior to ICS OEMs modified the Holo theme to their liking, while on ICS and newer Holo will be Google standard. So if the OEM has changed the theme on ICS, and you are using Holo, your app will not look consistent with the rest of the device!

Again, we create a styles.xml file, this time for API level 14, so in the res/values-v14 folder:

Code
#
1
<?xml version="1.0" encoding="utf-8"?>
2
<resources>
3
    <style 
4
        name="Theme.Chainfire" 
5
        parent="android:Theme.DeviceDefault">
6
    </style>
7
    <style 
8
        name="Theme.Chainfire.NoTitleBar"
9
        parent="android:Theme.DeviceDefault.NoActionBar">
10
    </style>
11
    <style 
12
        name="Theme.Chainfire.Fullscreen"
13
        parent="android:Theme.DeviceDefault.NoActionBar.Fullscreen">
14
    </style>
15
</resources>

Step 5: Make your activities use the theme

This is quite simple. Open your AndroidManifest.xml file, it should look something like this:

Code
#
1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest ...>
3
    <application ...>
4
        <activity ...
5
            android:theme="@style/Theme.Chainfire">
6
            ...
7
        </activity
8
    </application>
9
</manifest>

It is literally as easy as adding the android:theme attribute to each of your activities. Ofcourse, instead of Theme.Chainfire, you could also have used Theme.Chainfire.NoTitleBar or Theme.Chainfire.Fullscreen

Modifications

I have called these themes Theme.Chainfire.xxx, you can of course rename them to whatever you want to call them, but make sure you consistently change the name in all three styles.xml files.

I have also opted to use the dark theme variants. There are also light variants (Theme.Light, Theme.Holo.Light, Theme.DeviceDefault.Light) you can use instead, but be aware the dark variants are usually the device default.

If you are using ActionBarSherlock in your app, this simple solution does not work and needs further adaptation.

Recap

  • Set target API level to 14
  • Create res/values/styles.xml (Black)
  • Create res/values-v11/styles.xml (Holo)
  • Create res/values-v14/styles.xml (DeviceDefault)
  • Add android:theme to your activities in AndroidManifest.xml

Notes

After making these modifications, you will most likely have to Clean your project in Eclipse (Project -> Clean) for the changes to take effect. Often the build system will not recognize changes to xml files by itself.

Comments

Posted by Sinan on 04-01-2012 at 11:03:36
Very good article, thanks ChainFire
Posted by maeganpilz on 04-09-2014 at 06:33:18
I believe firmly regarding this and so really enjoy understanding more about this kind of subject. buy youtube views from http://socialformula.com Thanks :)
Posted by sd on 08-10-2014 at 06:07:02
Android is popular with technology companies which require a ready-made, low-cost and customizable operating system for high-tech devices.
<a href="http://www.amazon.com/Pure-Moroccan-Argan-Root-Sprouts/dp/B00LMH2GB6">amazon.com</a>
Posted by petaka on 17-10-2014 at 02:10:53
Everyone loves the idea when people get together in addition to talk about views. Wonderful website, stick with it!
motornimbo
http://www.kiwibox.com/smart77/blogkiwibox
Posted by Terry John on 04-11-2014 at 03:09:44
I like black theme on my android version. Many people do. Your instructions are pretty good and informative. I will change my theme from standard to fullscreen theme. Is there any app for updating us on college paper writing service reviews. Thanks for sharing.
Posted by college essay writer on 20-11-2014 at 12:29:07
Posted by asdf on 27-11-2014 at 20:10:02
<a class="mmcode_a" href="http://buyessayinc.com">professional essay</a> thanks.
Posted by Mike on 27-11-2014 at 20:11:23
Thanks. <a href="http://www.bestessayservicesreviews.com">college paper writing service reviews</a>
Posted by asdf on 27-11-2014 at 20:12:02
http://www.myessay.bizget essay writing service
Posted by Rdokoye on 30-11-2014 at 16:41:21
Looks like a fairly drawn out process, I think some kind of illustration or video footage would make it easier to follow, much like my article on http://www.compuchenna.co.uk/fix-print-spoolerfixing printer spooler issues
Posted by tommy on 08-12-2014 at 16:06:52
Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.http://www.irepliquemontresluxe.com
Posted by Air-K on 20-12-2014 at 06:34:20
We could keep using Holo, Often the build system will not recognize changes to xml files by itself.<a href="http://orologiperfetto.webnode.it/" target="_blank">Rolex Replica</a>
Posted by U-Boatking on 20-12-2014 at 06:35:41
you could also have used Theme. when people get together in addition to talk about views.http://belleorologi.beepworld.itreplica rolex
Posted by Jerry Jims on 29-12-2014 at 03:10:05
There are so many aspects to this, and you have opened up another train of thought for me to examine. Thank you for your insight. 247virtualassistants.com
Posted by Ken Anderson on 30-12-2014 at 05:31:39
I researched valuable information on this point as I am working on a class project. Thank you posting useful information and its now becoming easier to accomplish this task. Cinta Pos Cirurgica Yoga
Posted by Sara Tim on 30-12-2014 at 22:35:09
I am preparing a research paper and collecting information on this topic. Your post is one of the better that I have read. Thank you for putting this information into one post. http://www.tucsonimmigrationlawyers.coariano and reppucci pllc
Posted by bubblegum casting on 14-01-2015 at 22:01:19
you could also have used Theme. when people get together in addition to talk about views. <a href="http://talent.adweek.com/gallery/22281537/bubblegumcasting">bubblegum casting</a>http://talent.adweek.com/gallery/22281537/bubblegumcasting
Posted by bubblegum casting on 14-01-2015 at 22:02:10
such an interesting article here Afatogel.com Bandar Terbesar Situs Togel Online Terpercaya. I was searching for something like that for quite a long time and at last I have found it here.bubblegum casting
Posted by balidriver on 18-01-2015 at 21:49:32
I been looking this information
thank you for shared this useful post
Bali Driver and Bali Tours
Posted by malusamakucing on 03-03-2015 at 09:36:53
Saksikan <a href="http://www.vidio.com/tags/5165-drama-korea" >nonton drama korea online indonesian subtitle untuk semua</a> vidio.com<br>
Saksikan <a href="http://www.vidio.com/categories/30-tutorial" >video tutorial make up natural untuk kulit sawo matang untuk semua</a> vidio.com<br>
Saksikan <a href="http://www.vidio.com/categories/32-entertainment" >video gosip terbaru aliando dan prilly untuk semua</a> vidio.com<br>
Saksikan <a href="http://www.vidio.com/users/sctv/channels/10-ganteng-ganteng-serigala" >video ganteng ganteng serigala episode terakhir untuk semua</a> vidio.com<br>
Posted by malusamakucing on 03-03-2015 at 09:37:36
temukan <a href="http://tinyurl.com/vidfilm" rel="index,follow">nonton film online subtitle indonesia tanpa download</a> vidio.com
temukan <a href="http://tinyurl.com/vidfilm" rel="index,follow">nonton movie online sub indo</a> vidio.com
temukan <a href="http://tinyurl.com/vidfun" rel="index,follow">video lucu banget bikin ngakak abis</a> vidio.com
temukan <a href="http://tinyurl.com/vidmusik" rel="index,follow">video musik dangdut koplo pantura</a> vidio.com
temukan <a href="http://tinyurl.com/vidmusik" rel="index,follow">video klip musik barat terbaik sepanjang masa</a> vidio.com
Posted by john on 25-03-2015 at 05:38:14
When compared to previous style, possesses slimmer biceps and a greater repertoire associated with words and phrases. Once hard-wired, it is able to choreograph it's motions in addition to motions with its voice.
<a href="http://www.webryzeseoservices.ca">http://www.webryzeseoservices.ca</a>
Posted by asasas on 25-03-2015 at 05:39:39
When compared to previous style, possesses slimmer biceps and a greater repertoire associated with words and phrases. Once hard-wired, it is able to choreograph it's motions in addition to motions with its voice.
http://www.webryzeseoservices.ca
Posted by sas on 02-04-2015 at 05:02:38
That is very interesting Smile I love reading and I Cipto Junaedy always searching for informative information like this Jadwal MotoGP 2015. This is exactly what I was looking for Cara Upload Video ke Youtube.  Really this system so amazing. Cipto Junaedy  so happy to browsing this BBM Untuk Android Versi Terbaru. Simply fill out a quick and easy application, and you'll be on your way to getting your new Cara Membuat Email  and Cara Instal Windows 7 avoiding Thanks for sharing this great article . Don't forget for reading the articles about Jinpoker.com Agen Judi Poker Online dan Domino Online Indonesia Terpercaya. And I encourage you to bookmark the following page if Cahayapoker.com Agen Judi Poker Dan Domino Uang Asli Online Terpercaya Indonesia considered important ... Regards ituDewa.net Agen Judi Poker Domino QQ Ceme Online Indonesia | Nusantarapoker.com Agen Texas Poker Dan Domino Online Tanpa Robot Terpercaya
Posted by kapilsharma on 02-04-2015 at 05:11:47
When compared to previous vogue, possesses slimmer striated muscle and a larger repertoire related to words and phrases. <a href="http://ranklikes.com/buy-facebook-ratings-reviews/">buy facebook ratings</a>
Posted by kapil on 02-04-2015 at 05:12:37
Posted by ranklikes on 11-04-2015 at 03:26:16
really cool stuff even though i didn't follow the coding. i really love to do this king of things but where do i get the knowledge and what languages should i learn. any resources would be hugely appreciated.
http://reseprumpi.bravesites.com
https://resepcita.wordpress.com
https://www.rebelmouse.com/tati91
http://tassresep.soup.io
Posted by jani on 16-05-2015 at 04:51:12
http://blog.cashinyourgadgets.co.uk/ : Find out how much you could earn for your old laptop with Cash in your Gadgets.
Posted by Allenwood on 16-05-2015 at 04:51:42
[http://www.cashinyourgadgets.co.uk/gadget-library/brand/laptops], [sell my laptop]
Posted by Allen on 16-05-2015 at 04:53:28
http://www.cashinyourgadgets.co.uk/gadget-library/brand/laptops
Posted by Karlo on 01-06-2015 at 16:58:04
Very informative post thanks for share this with us I highly appreciate you for this information thanks once again for sharing information like this! http://www.utopia-almelo.nl/kantoor-kantoorruimte-huren-twentekantoorruimte huren Almelo
Posted by sheila on 05-06-2015 at 01:05:15
I found some very interesting information in your article and definitely reading this was well-worth the time. festa da peppa pig
Posted by uali20 on 06-06-2015 at 10:54:46
Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. http://thevenusfactorreviewsx.comhttp://thevenusfactorreviewsx.com/
Posted by girlsdoporn on 06-06-2015 at 19:00:13
This is really a nice and informative, containing all information and also has a great impact on the new technology. girlsdoporn
Posted by girlsdoporn on 08-06-2015 at 02:13:57
Cool you inscribe, the info is really salubrious further fascinating, I'll give you a connect to my scene. girlsdoporn
Posted by kate john on 19-06-2015 at 11:35:39
this is really great,unique and very informative post, i like it. thanks essay writing service essay help
Posted by Reiza on 24-06-2015 at 04:18:47
Excellent post, The post is written in very a good manner and it entails many useful information for me.
http://tayuji.soup.io/
https://rineganlox.wordpress.comhttps://rineganlox.wordpress.com/
http://butterydeliciouspatrol.tumblr.comhttp://butterydeliciouspatrol.tumblr.com/
http://uchihalumia.pun.bzhttp://uchihalumia.pun.bz/
https://storify.com/yatijuni
Posted by Yui on 24-06-2015 at 04:27:26
thanks
https://rineganlox.wordpress.com
Posted by girlsdoporn on 29-06-2015 at 05:21:23
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! Itâs always nice when you can not only be informed, but also entertained! girlsdoporn
Posted by new year 2016 on 01-07-2015 at 15:13:20
Posted by girlsdoporn on 02-07-2015 at 04:34:53
Love to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks. girlsdoporn
Posted by prince on 12-07-2015 at 16:17:09
this is truly great,unique and exceptionally educational post, i like it. much appreciated - http://massliker.com/
Posted by princedada on 12-07-2015 at 16:18:15
this is truly great,unique and exceptionally educational post, i like it. much appreciated http://massliker.combuy facebook photo likes
Posted by dadadda on 17-07-2015 at 11:08:56
This is truly a decent and enlightening, containing all data furthermore has an awesome [http://ranklikes.com/]
Posted by dadadda on 17-07-2015 at 11:09:35
<a href="http://ranklikes.com/"> buy usa facebook likes</a>
Posted by dadadda on 17-07-2015 at 11:10:11
Posted by Sujata Roy on 18-07-2015 at 07:16:04
Thanks for Nice and Informative Post. This article is really contains lot more information about This Topic
http://www.top9th.in/packers-and-movers-bangalore/
http://www.top9th.in/packers-and-movers-hyderabad/
http://www.top9th.in/packers-and-movers-mumbai/
http://www.top9th.in/packers-and-movers-delhi/
http://www.top9th.in/packers-and-movers-gurgaon/
Posted by Sujata Roy on 18-07-2015 at 07:18:21
Thanks for post this helpful post - Please visit for More information about:
http://www.top9th.in/packers-and-movers-pune/
http://www.top9th.in/packers-and-movers-noida/
http://www.top9th.in/packers-and-movers-chennai/
http://www.top9th.in/packers-and-movers-kolkata/
http://www.top9th.in/packers-and-movers-ahmedabad/
http://www.top9th.in/packers-and-movers-surat/
Posted by jassica on 23-07-2015 at 09:39:04
Business commercial collection agency has are more important since businesses of most sizes are usually experiencing ever-increasing overdue payments and also unpaid negative debt attributable to a lethargic economy. http://www.business-debt-collection.combusiness-debt-collection.com
Posted by jassica on 23-07-2015 at 09:39:56
Explaining reasons why Online MLM is probably the top enterprise ideas nowadays. In addition offers you an thought how to succeed in Network Marketing and advertising leveraging the net. http://www.top10business.nettop10business.net
Posted by jassica on 23-07-2015 at 09:40:32
A business advance loan is funds borrowed in opposition to your bank card balance. The bucks advance could be lower as compared to your credit limit. There can be a fee or mortgage associated with cash advances.
http://www.businesscashadvanced.netbusinesscashadvanced.net
Posted by jassica on 23-07-2015 at 09:40:57
The expenses of participating in college today continues to skyrocket. Many students have found it extremely hard to finance their particular education. Science & Technology
Posted by jassica on 23-07-2015 at 09:41:19
Whilst invention is worried with the particular creation of guidelines, innovation involves the creation regarding ideas as well as the transformation of the into cheaply viable, market focused products. Discorery & Innovation
Posted by nomanyk on 23-07-2015 at 20:47:46
I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. <a href="http://www.levinlaw.com/practice-areas/securities-investment-fraud-attorneys">Securities fraud lawyer</a>
Posted by nomanyk on 23-07-2015 at 20:48:50
Posted by nomanyk on 23-07-2015 at 20:49:35
This is a Nice Post. Securities fraud lawyer
Posted by Xarelto Bleeding Lawsuits on 23-07-2015 at 21:03:06
Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information.. https://www.xareltocares.com/xarelto-bleeding-effectsXarelto Bleeding Lawsuits
Posted by nomanyk on 23-07-2015 at 21:04:14
Thanks so much with this fantastic new web site. Iâm very fired up to show it to anyone. It makes me so satisfied your vast understanding and wisdom have a new channel for trying into the world. https://www.xareltocares.com/xarelto-bleeding-effectsXarelto Bleeding Lawsuits
Posted by nomanyk on 23-07-2015 at 21:05:28
You actually make it look so easy with your performance but I find this matter to be actually. Xarelto Bleeding Lawsuits
Posted by Manoj Kumar on 24-07-2015 at 18:56:34
Posted by Manoj Kumar on 24-07-2015 at 19:02:05
Posted by Ambika Jaiswal on 24-07-2015 at 19:08:01




(This is a trap for bad people - don't input website)




You may use tags like [b], [u], [i], [url], [quote], [code], [pre], etc