How to set a theme to whole application in code, but not in the Manifest?

前端 未结 6 1522
萌比男神i
萌比男神i 2020-12-16 17:11

I know how to set theme to whole application in manifest,but how to set theme to whole application programmatically ? I am trying this: getApplicationContext.se

6条回答
  •  鱼传尺愫
    2020-12-16 17:59

    You can't apply it to a whole application from Java, unless you use Java code to modify the manifest file. The other activities you want to apply the theme to might not even be running so how would Android apply a theme to them? And after exiting and returning to your program all the changes would be lost and you'd need to apply the theme again.

    getApplicationContext does return the application context - but just because a method takes a Context doesn't mean that passing it an ApplicationContext will suddenly make it affect the whole application. In fact in general it won't, and will just work as if you used a normal Context.

    Rather the importance of the different contexts is that they are around for different amounts of time - an activity context is created and destroyed with the activity, but an Application context is created when the first application component runs and destroyed when the last component is destroyed.

提交回复
热议问题