In Android, you can get the current theme of an activity as a Resource.Theme
object from getTheme()
. Also, you can set the theme to a different one via that other theme's resource id, as in setTheme(R.style.Theme_MyTheme)
.
But how do I find out whether it's worth it -- whether the current theme is already the one that I would want to set? I am looking for something like getTheme().getResourceId()
, in order to write something like:
protected void onResume() {
int newThemeId = loadNewTheme();
if (newThemeId != getTheme().getResourceId()) { // !!!! How to do this?
setTheme(newThemeId);
// and rebuild the gui, which is expensive
}
}
Any ideas?