ContextThemeWrapper
public class ContextThemeWrapper extends ContextWrapper
| java.lang.Object | |||
| ↳ | android.content.Context | ||
| ↳ | android.content.ContextWrapper | ||
| ↳ | androidx.appcompat.view.ContextThemeWrapper |
A context wrapper that allows you to modify or replace the theme of the wrapped context.
Summary
Public constructors |
|---|
|
Creates a new context wrapper with no theme and no base context. |
ContextThemeWrapper(Context base, @StyleRes int themeResId)Creates a new context wrapper with the specified theme. |
ContextThemeWrapper(Context base, Resources.Theme theme)Creates a new context wrapper with the specified theme. |
Public methods |
|
|---|---|
void |
applyOverrideConfiguration(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. |
AssetManager |
|
Resources |
|
Object |
getSystemService(String name) |
Resources.Theme |
getTheme() |
int |
Returns the resource ID of the theme that is to be applied on top of the base context's theme. |
void |
setTheme(int resid) |
Protected methods |
|
|---|---|
void |
attachBaseContext(Context newBase) |
void |
onApplyThemeResource(Resources.Theme theme, int resid, boolean first)Called by setTheme and getTheme to apply a theme resource to the current Theme object. |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
ContextThemeWrapper
public ContextThemeWrapper()
Creates a new context wrapper with no theme and no base context.
Note: A base context must be attached using attachBaseContext before calling any other method on the newly constructed context wrapper.
ContextThemeWrapper
public ContextThemeWrapper(Context base, @StyleRes int themeResId)
Creates a new context wrapper with the specified theme.
The specified theme will be applied on top of the base context's theme. Any attributes not explicitly defined in the theme identified by themeResId will retain their original values.
ContextThemeWrapper
public ContextThemeWrapper(Context base, Resources.Theme theme)
Creates a new context wrapper with the specified theme.
Unlike ContextThemeWrapper, the theme passed to this constructor will completely replace the base context's theme.
| Parameters | |
|---|---|
Context base |
the base context |
Resources.Theme theme |
the theme against which resources should be inflated |
Public methods
applyOverrideConfiguration
public void applyOverrideConfiguration(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 createConfigurationContext for more information.
This method can only be called once, and must be called before any calls to getResources or getAssets are made.
getThemeResId
public int getThemeResId()
Returns the resource ID of the theme that is to be applied on top of the base context's theme.
Protected methods
onApplyThemeResource
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first)
Called by setTheme and 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.
| Parameters | |
|---|---|
Resources.Theme theme |
The Theme object being modified. |
int resid |
The theme style resource being applied to theme. |
boolean first |
Set to true if this is the first time a style is being applied to theme. |