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
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 ()

public ContextThemeWrapper (Context base, int themeres)

Public Methods

public 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.
INPUT_METHOD_SERVICE ("input_method")
An InputMethodManager for management of input methods.

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 ()

Return the Theme object associated with this Context.

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

Protected Methods

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

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