公共无效setTheme(int resid)
为此上下文设置基本主题.请注意,这应该称为
在Context中实例化任何视图之前(例如
调用setContentView(View)或inflate(int,ViewGroup)).
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)).
因此,在调用setContentView()
之前,必须先用setTheme()
设置主题,之后才能进行更改.您唯一的选择是重新创建Activity
.
So you have to set the theme with setTheme()
before calling setContentView()
, after that it is impossible to change it. Your only option is to recreate the Activity
.
顺便说一句:您说重新创建Activity
并不是一种选择,这很不可思议,Activities
具有明确的生命周期,并且通过遵守该生命周期,应该可以重新创建Activity
或您或Android OS想要的频率.实际上,您应该知道Activity
可以随时被Android OS杀死并重新创建,这实际上是Android的正常现象.因此,重新创建Activity
并不是一种选择,这似乎表明您的应用程序设计中存在一个更深层次的根源问题,如果不解决的话,它仍然会表现出来.
As an aside: That you say that recreating the Activity
is not an option seems weird, Activities
have a well defined life cycle and by adhering to this life cycle it should be possible to recreate the Activity
how ever often you or the Android OS wants to. In fact you should know that your Activity
can be killed and recreated by the Android OS at any moment and this is in fact a normal and expected behaviour of Android. So that recreating the Activity
is not an option seems to indicate a much deeper rooted problem in your apps design that will manifest itself anyway if not solved.