How to set a theme at runtime?

Please, does anyone know how to install the theme using runtime? getApplication (). does setTheme () not set a topic?

How can I set a theme when the user selects a button and it will install the theme in my application?

+4
source share
3 answers

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

+3
source

I have not tried this, but here is the documentation for ContextWrapper.setTheme (int) :

public void setTheme (int resid)

C: API Level 1 Define a base theme for this context. Please note that this should be called before any created in the context (for example, before calling setContentView (View) or inflating (int, ViewGroup)).

Based on this description, the action needs to be destroyed and recreated (as usual, when changing orientation or other configuration), then call setTheme () inside onCreate ().

+2
source

There is an open Google Android problem for this: it seems like an open error that you cannot programmatically change the theme using setTheme (). http://code.google.com/p/android/issues/detail?id=4394

0
source

Source: https://habr.com/ru/post/1345545/


All Articles