Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ContextThemeWrapper

public class ContextThemeWrapper
extends ContextWrapper

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
Known Direct Subclasses
Known Indirect Subclasses


A ContextWrapper that allows you to modify the theme from what is in the wrapped context.

Summary

Inherited constants

From class android.content.Context

Public constructors

ContextThemeWrapper()
ContextThemeWrapper(Context base, int themeResId)
ContextThemeWrapper(Context base, Resources.Theme 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.

Resources getResources()

Return a Resources instance for your application's package.

Object getSystemService(String name)

Return the handle to a system-level service by name.

Resources.Theme getTheme()

Return the Theme object associated with this Context.

void setTheme(int resid)

Set the base theme for this context.

Protected methods

void attachBaseContext(Context newBase)

Set the base context for this ContextWrapper.

void onApplyThemeResource(Resources.Theme theme, int resid, boolean first)

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

Inherited methods

From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object

Public constructors

ContextThemeWrapper

Added in API level 1
ContextThemeWrapper ()

ContextThemeWrapper

Added in API level 1
ContextThemeWrapper (Context base, 
                int themeResId)

Parameters
base Context
themeResId int

ContextThemeWrapper

Added in API level 23
ContextThemeWrapper (Context base, 
                Resources.Theme theme)

Parameters
base Context
theme Resources.Theme

Public methods

applyOverrideConfiguration

Added in API level 17
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(Configuration) for more information.

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

Parameters
overrideConfiguration Configuration

getResources

Added in API level 1
Resources getResources ()

Return a Resources instance for your application's package.

Returns
Resources

getSystemService

Added in API level 1
Object getSystemService (String name)

Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are:

WINDOW_SERVICE ("window")
The top-level window manager in which you can place custom windows. The returned object is a WindowManager.
LAYOUT_INFLATER_SERVICE ("layout_inflater")
A LayoutInflater for inflating layout resources in this context.
ACTIVITY_SERVICE ("activity")
A ActivityManager for interacting with the global activity state of the system.
POWER_SERVICE ("power")
A PowerManager for controlling power management.
ALARM_SERVICE ("alarm")
A AlarmManager for receiving intents at the time of your choosing.
NOTIFICATION_SERVICE ("notification")
A NotificationManager for informing the user of background events.
KEYGUARD_SERVICE ("keyguard")
A KeyguardManager for controlling keyguard.
LOCATION_SERVICE ("location")
A LocationManager for controlling location (e.g., GPS) updates.
SEARCH_SERVICE ("search")
A SearchManager for handling search.
VIBRATOR_SERVICE ("vibrator")
A Vibrator for interacting with the vibrator hardware.
CONNECTIVITY_SERVICE ("connection")
A ConnectivityManager for handling management of network connections.
WIFI_SERVICE ("wifi")
A WifiManager for management of Wi-Fi connectivity.
WIFI_P2P_SERVICE ("wifip2p")
A WifiP2pManager for management of Wi-Fi Direct connectivity.
INPUT_METHOD_SERVICE ("input_method")
An InputMethodManager for management of input methods.
UI_MODE_SERVICE ("uimode")
An UiModeManager for controlling UI modes.
DOWNLOAD_SERVICE ("download")
A DownloadManager for requesting HTTP downloads
BATTERY_SERVICE ("batterymanager")
A BatteryManager for managing battery state
JOB_SCHEDULER_SERVICE ("taskmanager")
A JobScheduler for managing scheduled tasks
NETWORK_STATS_SERVICE ("netstats")
A NetworkStatsManager for querying network usage statistics.

Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)

Parameters
name String: The name of the desired service.
Returns
Object The service or null if the name does not exist.

getTheme

Added in API level 1
Resources.Theme getTheme ()

Return the Theme object associated with this Context.

Returns
Resources.Theme

setTheme

Added in API level 1
void setTheme (int resid)

Set the base theme for this context. Note that this should be called before any views are instantiated in the Context (for example before calling setContentView(View) or inflate(int, ViewGroup)).

Parameters
resid int: The style resource describing the theme.

Protected methods

attachBaseContext

Added in API level 1
void attachBaseContext (Context newBase)

Set the base context for this ContextWrapper. All calls will then be delegated to the base context. Throws IllegalStateException if a base context has already been set.

Parameters
newBase Context: The new base context for this wrapper.

onApplyThemeResource

Added in API level 1
void onApplyThemeResource (Resources.Theme theme, 
                int resid, 
                boolean first)

Called by setTheme(int) 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 Resources.Theme: The Theme object being modified.
resid int: The theme style resource being applied to theme.
first boolean: Set to true if this is the first time a style is being applied to theme.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.