Reputation: 1580
Please Anyone know how to set theme using runtime? getApplication().setTheme() not set theme?
How can i set theme when user select the button and it will set the theme in my application?
Upvotes: 4
Views: 4355
Reputation: 3969
you can use setTheme(..)
before calling setContentView(...)
and super.oncreate()
and it should work fine
Upvotes: 3
Reputation: 684
There is an open Google Android issue for this: it appears to be an open bug that you cannot programmatically change the theme with setTheme(). http://code.google.com/p/android/issues/detail?id=4394
Upvotes: 0
Reputation: 4527
I haven't tried this, but here is the documentation for ContextWrapper.setTheme(int):
public void setTheme (int resid)
Since: API Level 1 Set the base theme for this context. Note that this should be called before any views are instantiated in the Context (for example before calling setContentView(View) or inflate(int, ViewGroup)).
Based on this description, the activity needs to be destroyed and recreated (as it would normally on an orientation or other configuration change), then call setTheme() within onCreate().
Upvotes: 2