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.setTheme(R.style.mytheme), but it doesn’t work.
I think the getApplicationContext is the Application’s Context, which can set whole application theme.
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.
getApplicationContextdoes return the application context – but just because a method takes aContextdoesn’t mean that passing it anApplicationContextwill 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.