Added in API level 1

ContextThemeWrapper

open class ContextThemeWrapper : ContextWrapper
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.view.ContextThemeWrapper

A context wrapper that allows you to modify or replace the theme of the wrapped context.

Summary

Inherited constants
Public constructors

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

ContextThemeWrapper(base: Context!, themeResId: Int)

Creates a new context wrapper with the specified 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 Resources.Theme!

open Unit
setTheme(resid: Int)

open Unit

Set the configure the current theme.

Protected methods
open Unit

open Unit
onApplyThemeResource(theme: Resources.Theme!, resId: Int, first: Boolean)

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

Inherited functions

Public constructors

ContextThemeWrapper

Added in API level 1
ContextThemeWrapper()

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

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

ContextThemeWrapper

Added in API level 1
ContextThemeWrapper(
    base: Context!,
    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 Int: the resource ID of the theme to be applied on top of the base context's theme

ContextThemeWrapper

Added in API level 1
ContextThemeWrapper(
    base: Context!,
    theme: Resources.Theme!)

Creates a new context wrapper with the specified theme.

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

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

Public methods

applyOverrideConfiguration

Added in API level 17
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

Added in API level 1
open fun getAssets(): AssetManager!
Return
AssetManager! an AssetManager instance for the application's package

getResources

Added in API level 1
open fun getResources(): Resources!
Return
Resources! a Resources instance for the application's package

getSystemService

Added in API level 1
open fun getSystemService(name: String): Any!
Parameters
name String: The name of the desired service. Value is android.content.Context#POWER_SERVICE, android.content.Context#WINDOW_SERVICE, android.content.Context#LAYOUT_INFLATER_SERVICE, android.content.Context#ACCOUNT_SERVICE, android.content.Context#ACTIVITY_SERVICE, android.content.Context#ALARM_SERVICE, android.content.Context#NOTIFICATION_SERVICE, android.content.Context#ACCESSIBILITY_SERVICE, android.content.Context#CAPTIONING_SERVICE, android.content.Context#KEYGUARD_SERVICE, android.content.Context#LOCATION_SERVICE, android.content.Context#HEALTHCONNECT_SERVICE, android.content.Context#SEARCH_SERVICE, android.content.Context#SENSOR_SERVICE, android.content.Context.SENSOR_PRIVACY_SERVICE, android.content.Context#STORAGE_SERVICE, android.content.Context#STORAGE_STATS_SERVICE, android.content.Context#WALLPAPER_SERVICE, android.content.Context#VIBRATOR_MANAGER_SERVICE, android.content.Context#VIBRATOR_SERVICE, android.content.Context.THREAD_NETWORK_SERVICE, android.content.Context#CONNECTIVITY_SERVICE, android.content.Context.PAC_PROXY_SERVICE, android.content.Context.VCN_MANAGEMENT_SERVICE, android.content.Context#IPSEC_SERVICE, android.content.Context#VPN_MANAGEMENT_SERVICE, android.content.Context.TEST_NETWORK_SERVICE, android.content.Context#NETWORK_STATS_SERVICE, android.content.Context#WIFI_SERVICE, android.content.Context#WIFI_AWARE_SERVICE, android.content.Context#WIFI_P2P_SERVICE, android.content.Context.WIFI_SCANNING_SERVICE, android.content.Context#WIFI_RTT_RANGING_SERVICE, android.content.Context#NSD_SERVICE, android.content.Context#AUDIO_SERVICE, android.content.Context.AUDIO_DEVICE_VOLUME_SERVICE, android.content.Context.AUTH_SERVICE, android.content.Context#FINGERPRINT_SERVICE, android.content.Context#BIOMETRIC_SERVICE, android.content.Context#MEDIA_ROUTER_SERVICE, android.content.Context#TELEPHONY_SERVICE, android.content.Context#TELEPHONY_SUBSCRIPTION_SERVICE, android.content.Context#CARRIER_CONFIG_SERVICE, android.content.Context#EUICC_SERVICE, android.content.Context#TELECOM_SERVICE, android.content.Context#CLIPBOARD_SERVICE, android.content.Context#INPUT_METHOD_SERVICE, android.content.Context#TEXT_SERVICES_MANAGER_SERVICE, android.content.Context#TEXT_CLASSIFICATION_SERVICE, android.content.Context#APPWIDGET_SERVICE, android.content.Context.REBOOT_READINESS_SERVICE, android.content.Context.ROLLBACK_SERVICE, android.content.Context#DROPBOX_SERVICE, android.content.Context#DEVICE_POLICY_SERVICE, android.content.Context#UI_MODE_SERVICE, android.content.Context#DOWNLOAD_SERVICE, android.content.Context#NFC_SERVICE, android.content.Context#BLUETOOTH_SERVICE, android.content.Context#USB_SERVICE, android.content.Context#LAUNCHER_APPS_SERVICE, android.content.Context#INPUT_SERVICE, android.content.Context#DISPLAY_SERVICE, android.content.Context#USER_SERVICE, android.content.Context#RESTRICTIONS_SERVICE, android.content.Context#APP_OPS_SERVICE, android.content.Context#ROLE_SERVICE, android.content.Context#CAMERA_SERVICE, android.content.Context#PRINT_SERVICE, android.content.Context#CONSUMER_IR_SERVICE, android.content.Context#TV_INTERACTIVE_APP_SERVICE, android.content.Context#TV_INPUT_SERVICE, android.content.Context#USAGE_STATS_SERVICE, android.content.Context#MEDIA_SESSION_SERVICE, android.content.Context#MEDIA_COMMUNICATION_SERVICE, android.content.Context#BATTERY_SERVICE, android.content.Context#JOB_SCHEDULER_SERVICE, android.content.Context#MEDIA_PROJECTION_SERVICE, android.content.Context#MIDI_SERVICE, android.content.Context.RADIO_SERVICE, android.content.Context#HARDWARE_PROPERTIES_SERVICE, android.content.Context#SHORTCUT_SERVICE, android.content.Context#SYSTEM_HEALTH_SERVICE, android.content.Context#COMPANION_DEVICE_SERVICE, android.content.Context#VIRTUAL_DEVICE_SERVICE, android.content.Context#CROSS_PROFILE_APPS_SERVICE, android.content.Context.PERMISSION_SERVICE, android.content.Context.LIGHTS_SERVICE, android.content.Context#LOCALE_SERVICE, android.content.Context.UWB_SERVICE, android.content.Context#MEDIA_METRICS_SERVICE, android.content.Context#DISPLAY_HASH_SERVICE, android.content.Context#CREDENTIAL_SERVICE, android.content.Context#DEVICE_LOCK_SERVICE, android.content.Context.VIRTUALIZATION_SERVICE, android.content.Context#GRAMMATICAL_INFLECTION_SERVICE, or android.content.Context.SECURITY_STATE_SERVICE This value cannot be null.
Return
Any! The service or null if the name does not exist.

getTheme

Added in API level 1
open fun getTheme(): Resources.Theme!

setTheme

Added in API level 1
open fun setTheme(resid: Int): Unit
Parameters
resid Int: The style resource describing the theme.

setTheme

Added in API level 29
open fun setTheme(theme: Resources.Theme?): Unit

Set the configure the current theme. If null is provided then the default Theme is returned on the next call to #getTheme()

Parameters
theme Resources.Theme?: Theme to consume in the wrapper, a value of null resets the theme to the default

Protected methods

attachBaseContext

Added in API level 1
protected open fun attachBaseContext(newBase: Context!): Unit
Parameters
base The new base context for this wrapper.

onApplyThemeResource

Added in API level 1
protected open fun onApplyThemeResource(
    theme: Resources.Theme!,
    resId: Int,
    first: Boolean
): Unit

Called by #setTheme and #getTheme to apply a theme resource to the current Theme object. May be overridden to change the default (simple) behavior. This method will not be called in multiple threads simultaneously.

Parameters
theme Resources.Theme!: the theme being modified
resId Int: the style resource being applied to theme
first Boolean: true if this is the first time a style is being applied to theme