in my application I would to change background and text colour (for example in Google Sky Map application you can set the “night mode” that changes background and text colour), how can I do the same thing using the same layout for both changes? I would to change also some text (for example I write Italian words and I would to change it in English words) if it’s possible. Could some help me giving any tutorial, example or code? Thank you so much.
Share
You can programmatically change text and background colors using specific methods on controls like:
But that would be one by one. You can create a couple of styles, but unfortunately setting the style of a widget after it’s been constructed is tedious because you’d have to make individual calls just like you did above:
Finally there are Themes which are collections of Styles defined in resources that define all of your UI. Themes can be set at once when an activity is created:
http://developer.android.com/guide/topics/ui/themes.html
Choosing a style / theme programmatically at run time
As for text you can easily externalize your text using the strings.xml resource, and keep an italian version and english version, and Android will use the correct version that best corresponds with the user’s locale settings. There is a default strings.xml which will be used if Android can’t find a matching strings resource for the user’s locale. Its usually a good idea to default to english for strings.xml, and create a strings_it.xml for italian.
http://developer.android.com/guide/topics/resources/index.html