FileDocCategorySizeDatePackage
ContextThemeWrapper.javaAPI DocAndroid 5.1 API4726Thu Mar 12 22:22:10 GMT 2015android.view

ContextThemeWrapper

public class ContextThemeWrapper extends android.content.ContextWrapper
A ContextWrapper that allows you to modify the theme from what is in the wrapped context.

Fields Summary
private int
mThemeResource
private Resources.Theme
mTheme
private LayoutInflater
mInflater
private android.content.res.Configuration
mOverrideConfiguration
private android.content.res.Resources
mResources
Constructors Summary
public ContextThemeWrapper()

        super(null);
    
public ContextThemeWrapper(android.content.Context base, int themeres)

        super(base);
        mThemeResource = themeres;
    
Methods Summary
public voidapplyOverrideConfiguration(android.content.res.Configuration overrideConfiguration)
Call to set an "override configuration" on this context -- this is a configuration that replies one or more values of the standard configuration that is applied to the context. See {@link Context#createConfigurationContext(Configuration)} for more information.

This method can only be called once, and must be called before any calls to {@link #getResources()} are made.

        if (mResources != null) {
            throw new IllegalStateException("getResources() has already been called");
        }
        if (mOverrideConfiguration != null) {
            throw new IllegalStateException("Override configuration has already been set");
        }
        mOverrideConfiguration = new Configuration(overrideConfiguration);
    
protected voidattachBaseContext(android.content.Context newBase)

        super.attachBaseContext(newBase);
    
public android.content.res.ResourcesgetResources()

        if (mResources != null) {
            return mResources;
        }
        if (mOverrideConfiguration == null) {
            mResources = super.getResources();
            return mResources;
        } else {
            Context resc = createConfigurationContext(mOverrideConfiguration);
            mResources = resc.getResources();
            return mResources;
        }
    
public java.lang.ObjectgetSystemService(java.lang.String name)

        if (LAYOUT_INFLATER_SERVICE.equals(name)) {
            if (mInflater == null) {
                mInflater = LayoutInflater.from(getBaseContext()).cloneInContext(this);
            }
            return mInflater;
        }
        return getBaseContext().getSystemService(name);
    
public Resources.ThemegetTheme()

        if (mTheme != null) {
            return mTheme;
        }

        mThemeResource = Resources.selectDefaultTheme(mThemeResource,
                getApplicationInfo().targetSdkVersion);
        initializeTheme();

        return mTheme;
    
public intgetThemeResId()

hide

        return mThemeResource;
    
private voidinitializeTheme()

        final boolean first = mTheme == null;
        if (first) {
            mTheme = getResources().newTheme();
            Resources.Theme theme = getBaseContext().getTheme();
            if (theme != null) {
                mTheme.setTo(theme);
            }
        }
        onApplyThemeResource(mTheme, mThemeResource, first);
    
protected voidonApplyThemeResource(Resources.Theme theme, int resid, boolean first)
Called by {@link #setTheme} and {@link #getTheme} to apply a theme resource to the current Theme object. Can override to change the default (simple) behavior. This method will not be called in multiple threads simultaneously.

param
theme The Theme object being modified.
param
resid The theme style resource being applied to theme.
param
first Set to true if this is the first time a style is being applied to theme.

        theme.applyStyle(resid, true);
    
public voidsetTheme(int resid)

        mThemeResource = resid;
        initializeTheme();