FileDocCategorySizeDatePackage
ContextThemeWrapper.javaAPI DocAndroid 1.5 API3192Wed May 06 22:41:56 BST 2009android.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 android.content.Context
mBase
private int
mThemeResource
private Resources.Theme
mTheme
private LayoutInflater
mInflater
Constructors Summary
public ContextThemeWrapper()

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

        super(base);
        mBase = base;
        mThemeResource = themeres;
    
Methods Summary
protected voidattachBaseContext(android.content.Context newBase)

        super.attachBaseContext(newBase);
        mBase = newBase;
    
public java.lang.ObjectgetSystemService(java.lang.String name)

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

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

        if (mThemeResource == 0) {
            mThemeResource = com.android.internal.R.style.Theme;
        }
        initializeTheme();

        return mTheme;
    
private voidinitializeTheme()

        final boolean first = mTheme == null;
        if (first) {
            mTheme = getResources().newTheme();
            Resources.Theme theme = mBase.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();