# Print output for @column tags ?>
public
class
ContextThemeWrapper
extends ContextWrapper
java.lang.Object | |||
↳ | android.content.Context | ||
↳ | android.content.ContextWrapper | ||
↳ | android.view.ContextThemeWrapper |
Known indirect subclasses
AccountAuthenticatorActivity, ActivityGroup, AliasActivity, ExpandableListActivity, LauncherActivity, ListActivity, NativeActivity, PreferenceActivity, TabActivity
|
A context wrapper that allows you to modify or replace the theme of the wrapped context.
Inherited constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.content.Context
|
Public constructors | |
---|---|
ContextThemeWrapper()
Creates a new context wrapper with no theme and no base context. |
|
ContextThemeWrapper(Context base, int themeResId)
Creates a new context wrapper with the specified theme. |
|
ContextThemeWrapper(Context base, Resources.Theme theme)
Creates a new context wrapper with the specified 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. |
AssetManager
|
getAssets()
Returns an AssetManager instance for the application's package. |
Resources
|
getResources()
Returns a Resources instance for the 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(Resources.Theme theme)
Set the configure the current theme. |
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 |
Inherited methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.content.ContextWrapper
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.content.Context
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
java.lang.Object
|
public 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.
public ContextThemeWrapper (Context base, int themeResId)
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 |
public ContextThemeWrapper (Context base, Resources.Theme 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 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
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.
Parameters | |
---|---|
overrideConfiguration |
Configuration |
public AssetManager getAssets ()
Returns an AssetManager instance for the application's package.
Note: Implementations of this method should return
an AssetManager instance that is consistent with the Resources instance
returned by getResources()
. For example, they should share the
same Configuration
object.
Returns | |
---|---|
AssetManager |
an AssetManager instance for the application's package |
public Resources getResources ()
Returns a Resources instance for the application's package.
Note: Implementations of this method should return
a Resources instance that is consistent with the AssetManager instance
returned by getAssets()
. For example, they should share the
same Configuration
object.
Returns | |
---|---|
Resources |
a Resources instance for the application's package |
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")
WindowManager
. Must only be obtained
from a visual context such as Activity or a Context created with
createWindowContext(int, android.os.Bundle)
, which are adjusted to the configuration and
visual bounds of an area on screen.
LAYOUT_INFLATER_SERVICE
("layout_inflater")
LayoutInflater
for inflating layout resources
in this context. Must only be obtained from a visual context such as Activity or a Context
created with createWindowContext(int, android.os.Bundle)
, which are adjusted to the
configuration and visual bounds of an area on screen.
ACTIVITY_SERVICE
("activity")
ActivityManager
for interacting with the
global activity state of the system.
WALLPAPER_SERVICE
("wallpaper")
WallpaperService
for accessing wallpapers in this
context. Must only be obtained from a visual context such as Activity or a Context created
with createWindowContext(int, android.os.Bundle)
, which are adjusted to the configuration and
visual bounds of an area on screen.
POWER_SERVICE
("power")
PowerManager
for controlling power
management.
ALARM_SERVICE
("alarm")
AlarmManager
for receiving intents at the
time of your choosing.
NOTIFICATION_SERVICE
("notification")
NotificationManager
for informing the user
of background events.
KEYGUARD_SERVICE
("keyguard")
KeyguardManager
for controlling keyguard.
LOCATION_SERVICE
("location")
LocationManager
for controlling location
(e.g., GPS) updates.
SEARCH_SERVICE
("search")
SearchManager
for handling search.
VIBRATOR_MANAGER_SERVICE
("vibrator_manager")
VibratorManager
for accessing the device vibrators, interacting
with individual ones and playing synchronized effects on multiple vibrators.
VIBRATOR_SERVICE
("vibrator")
Vibrator
for interacting with the vibrator hardware.
CONNECTIVITY_SERVICE
("connectivity")
ConnectivityManager
for
handling management of network connections.
IPSEC_SERVICE
("ipsec")
IpSecManager
for managing IPSec on
sockets and networks.
WIFI_SERVICE
("wifi")
WifiManager
for management of Wi-Fi
connectivity. On releases before NYC, it should only be obtained from an application
context, and not from any other derived context to avoid memory leaks within the calling
process.
WIFI_AWARE_SERVICE
("wifiaware")
WifiAwareManager
for management of
Wi-Fi Aware discovery and connectivity.
WIFI_P2P_SERVICE
("wifip2p")
WifiP2pManager
for management of
Wi-Fi Direct connectivity.
INPUT_METHOD_SERVICE
("input_method")
InputMethodManager
for management of input methods.
UI_MODE_SERVICE
("uimode")
UiModeManager
for controlling UI modes.
DOWNLOAD_SERVICE
("download")
DownloadManager
for requesting HTTP downloads
BATTERY_SERVICE
("batterymanager")
BatteryManager
for managing battery state
JOB_SCHEDULER_SERVICE
("taskmanager")
JobScheduler
for managing scheduled tasks
NETWORK_STATS_SERVICE
("netstats")
NetworkStatsManager
for querying network
usage statistics.
HARDWARE_PROPERTIES_SERVICE
("hardware_properties")
HardwarePropertiesManager
for accessing hardware properties.
DOMAIN_VERIFICATION_SERVICE
("domain_verification")
DomainVerificationManager
for accessing
web domain approval state.
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.)
Note: Instant apps, for which PackageManager#isInstantApp()
returns true,
don't have access to the following system services: DEVICE_POLICY_SERVICE
,
FINGERPRINT_SERVICE
, KEYGUARD_SERVICE
, SHORTCUT_SERVICE
,
USB_SERVICE
, WALLPAPER_SERVICE
, WIFI_P2P_SERVICE
,
WIFI_SERVICE
, WIFI_AWARE_SERVICE
. For these services this method will
return null
. Generally, if you are running as an instant app you should always
check whether the result of this method is null
.
Note: When implementing this method, keep in mind that new services can be added on newer
Android releases, so if you're looking for just the explicit names mentioned above, make sure
to return null
when you don't recognize the name — if you throw a
RuntimeException
exception instead, you're app might break on new Android releases.
Returns | |
---|---|
Object |
The service or null if the name does not exist. |
public Resources.Theme getTheme ()
Return the Theme object associated with this Context.
Returns | |
---|---|
Resources.Theme |
public void setTheme (Resources.Theme theme)
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
This value may be null . |
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 Activity.setContentView(View)
or
LayoutInflater.inflate(int, ViewGroup)
).
Parameters | |
---|---|
resid |
int : The style resource describing the theme. |
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 |
Context : The new base context for this wrapper. |
protected void onApplyThemeResource (Resources.Theme theme, int resId, boolean first)
Called by setTheme(Resources.Theme)
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 |
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
Android 7.0 r1 —