1

Did anyone implemented multi theme support for android app? Are there any common practices for this?

Thanks for any advice.

UPD: The main problem for now is that android's theme engine doesn't support selectors like in CSS. For example if I have two views with "background" attribute there's no way to make theme engine distinguish those ones and set different backgrounds. I can specify different style for each view but this approach lacks flexibility 'cause it's impossible to apply style for whole activity at once.

3

1 Answer 1

3

As far as I know, there is no way to set a theme to the whole application in on line of code. If you want to change the theme of an activity, you need call setTheme() in its onCreate() method, BEFORE calling setContentView. So to make it easier for you, you could do a switch on all your themes, and select one in regards of what the user has selected. Now, if you want it to apply easily to all your activities, you could make all your activities be a subclass of a custom Activity in which you would only set the theme. Activity <-- ThemeActivity <-- all your Activities

5
  • Thanks. I've updated my original post. Maybe you can say something helpful now. Aug 13, 2010 at 12:27
  • I don't get your point about setting the style of a whole Activity... As i said above, setTheme sets the style for the whole activity.
    – Sephy
    Aug 13, 2010 at 12:31
  • I'm sorry, just meant theme saying style when told about activity. So do you know any way to emulate CSS selectors in android themes? Aug 13, 2010 at 12:52
  • Well, I think that android themes and styles work pretty much the same way as selectors though with less, less options.
    – Sephy
    Aug 13, 2010 at 12:56
  • Application.setTheme might do it as well
    – njzk2
    Nov 28, 2011 at 17:27

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.