diff options
-rw-r--r-- | core/java/android/app/ContextImpl.java | 24 | ||||
-rw-r--r-- | core/java/android/view/ContextThemeWrapper.java | 9 |
2 files changed, 24 insertions, 9 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 81a78f6..cb20cb8 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -237,8 +237,11 @@ class ContextImpl extends Context { } @Override - public void setTheme(int resid) { - mThemeResource = resid; + public void setTheme(int resId) { + if (mThemeResource != resId) { + mThemeResource = resId; + initializeTheme(); + } } @Override @@ -248,13 +251,22 @@ class ContextImpl extends Context { @Override public Resources.Theme getTheme() { + if (mTheme != null) { + return mTheme; + } + + mThemeResource = Resources.selectDefaultTheme(mThemeResource, + getOuterContext().getApplicationInfo().targetSdkVersion); + initializeTheme(); + + return mTheme; + } + + private void initializeTheme() { if (mTheme == null) { - mThemeResource = Resources.selectDefaultTheme(mThemeResource, - getOuterContext().getApplicationInfo().targetSdkVersion); mTheme = mResources.newTheme(); - mTheme.applyStyle(mThemeResource, true); } - return mTheme; + mTheme.applyStyle(mThemeResource, true); } @Override diff --git a/core/java/android/view/ContextThemeWrapper.java b/core/java/android/view/ContextThemeWrapper.java index 9047b1d..ce50091 100644 --- a/core/java/android/view/ContextThemeWrapper.java +++ b/core/java/android/view/ContextThemeWrapper.java @@ -87,9 +87,12 @@ public class ContextThemeWrapper extends ContextWrapper { } } - @Override public void setTheme(int resid) { - mThemeResource = resid; - initializeTheme(); + @Override + public void setTheme(int resid) { + if (mThemeResource != resid) { + mThemeResource = resid; + initializeTheme(); + } } /** @hide */ |