The Android Developer Challenge is back! Submit your idea before December 2.

ContextThemeWrapper

open class ContextThemeWrapper : ContextWrapper
kotlin.Any
   ↳ 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.

<init>(base: Context!, @StyleRes themeResId: Int)

Creates a new context wrapper with the specified theme.

<init>(base: Context!, theme: Theme!)

Creates a new context wrapper with the specified theme.

Public methods

open Unit
applyOverrideConfiguration(overrideConfiguration: Configuration!)

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.

open AssetManager!

open Resources!

open Any!

open Theme!

open Int

Returns the resource ID of the theme that is to be applied on top of the base context's theme.

open Unit
setTheme(resid: Int)

Protected methods

open Unit

open Unit
onApplyThemeResource(theme: Theme!, resid: Int, first: Boolean)

Called by setTheme and getTheme to apply a theme resource to the current Theme object.

Public constructors

<init>

ContextThemeWrapper()

Creates a new context wrapper with no theme and no base context.

Note: A base context must be attached using attachBaseContext(Context) before calling any other method on the newly constructed context wrapper.

<init>

ContextThemeWrapper(base: Context!, @StyleRes themeResId: Int)

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.

Parameters
base Context!: the base context
themeResId Context!: the resource ID of the theme to be applied on top of the base context's theme

<init>

ContextThemeWrapper(base: Context!, theme: Theme!)

Creates a new context wrapper with the specified theme.

Unlike ContextThemeWrapper(Context, int), the theme passed to this constructor will completely replace the base context's theme.

Parameters
base Context!: the base context
theme Context!: the theme against which resources should be inflated

Public methods

applyOverrideConfiguration

open fun applyOverrideConfiguration(overrideConfiguration: Configuration!): Unit

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 Context#createConfigurationContext(Configuration) for more information.

This method can only be called once, and must be called before any calls to getResources() or getAssets() are made.

getAssets

open fun getAssets(): AssetManager!

getResources

open fun getResources(): Resources!

getSystemService

open fun getSystemService(name: String!): Any!

getTheme

open fun getTheme(): Theme!

getThemeResId

open fun getThemeResId(): Int

Returns the resource ID of the theme that is to be applied on top of the base context's theme.

setTheme

open fun setTheme(resid: Int): Unit

Protected methods

attachBaseContext

protected open fun attachBaseContext(newBase: Context!): Unit

onApplyThemeResource

protected open fun onApplyThemeResource(theme: Theme!, resid: Int, first: Boolean): Unit

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
theme Theme!: The Theme object being modified.
resid Theme!: The theme style resource being applied to theme.
first Theme!: Set to true if this is the first time a style is being applied to theme.