Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

ContextThemeWrapper

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

Class Overview

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

Summary

[Expand]
Inherited Constants
From class android.content.Context
Public Constructors
ContextThemeWrapper ()
ContextThemeWrapper ( Context base, int themeres)
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.
[Expand]
Inherited Methods
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object

Public Constructors

public ContextThemeWrapper ()

Added in API level 1

public ContextThemeWrapper ( Context base, int themeres)

Added in API level 1

Public Methods

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

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

public Resources getResources ()

Added in API level 1

Return a Resources instance for your application's package.

public Object getSystemService ( String name)

Added in API level 1

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.
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

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 The name of the desired service.
Returns
  • The service or null if the name does not exist.

public Resources.Theme getTheme ()

Added in API level 1

Return the Theme object associated with this Context.

public void setTheme (int resid)

Added in API level 1

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 The style resource describing the theme.

Protected Methods

protected void attachBaseContext ( Context newBase)

Added in API level 1

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 The new base context for this wrapper.

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

Added in API level 1

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