Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose current theme on android

Tags:

android

I'm quite new to android dev and would like to know, how can I choose the current theme of the phone. I'm developing on the Galaxy Tab and the current theme is a nice white one (if I go into the settings menu for example). But the default theme in the sdk seems to be Android.Black.

I would prefer not to hardcode any choice and let the app use whichever one is chosen on the phone/tab...

like image 930
Mladen Mihajlovic Avatar asked Feb 23 '11 09:02

Mladen Mihajlovic


1 Answers

I'm not sure exactly what your question is aimed at, so I'll answer in two parts:

How do I let the app choose the current theme on Android?

The theme is set automatically (by default) to be whatever system theme the current device/user has selected. If no style or nested theme attributes are defined, then your app will be set to reflect the system style. For instance, if the default font color for the theme is #AFAFAF, the default font color for your app will also be #AFAFAF, unless otherwise specified by a style or theme resource.

If I don't like the current theme, how do I set my own theme?

You mentioned that you liked the nice white theme on the Galaxy tab. You are correct in that different versions of android use different system themes including fonts and backgrounds.

To get the current theme (to decide if it's the one you want), simply use the getApplication().getTheme(). If it's the theme you want, you don't have to do anything. If you want to apply logic and programatically set the theme, use the getApplication().setTheme([theme]) method to change it.

You can also specify both application-wide themes and themes for individual activities and you AndroidManifest.xml file as follows:

//for themes defined in res/values/style.xml    
<application android:theme="@style/myApplicationTheme"> 
<activity android:theme="@style/myApplicationTheme"> 
//for system themes
<application android:theme="@android:style/Theme.Light">
<activity android:theme="@android:style/Theme.Light">

And, as always, to individual view elements.

If you're looking to implement a specific system theme, be sure to check out the complete theme specifications. These will list all system themes as well as all defined style elements for each of the themes so you can use the desired theme or make your own variant.

If you're particularly fond of the light system theme, it can be set for your application using

<application android:theme="@android:style/Theme.Light">
like image 188
josh-cain Avatar answered Oct 19 '22 10:10

josh-cain