Jinesh
Jinesh

Reputation: 1580

How can i set theme at run time?

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

Answers (3)

Ahmed Salem
Ahmed Salem

Reputation: 3969

you can use setTheme(..) before calling setContentView(...)and super.oncreate() and it should work fine

Upvotes: 3

Lucy
Lucy

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

erichamion
erichamion

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

Related Questions