Most visited

Recently visited

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


上下文包装器,允许您修改或替换包装上下文的主题。

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)

调用以在此上下文中设置“覆盖配置” - 这是一种回复应用于上下文的标准配置的一个或多个值的配置。

AssetManager getAssets()

返回应用程序包的AssetManager实例。

Resources getResources()

返回应用程序包的资源实例。

Object getSystemService(String name)

按名称将句柄返回到系统级服务。

Resources.Theme getTheme()

返回与此上下文关联的主题对象。

void setTheme(int resid)

为此上下文设置基本主题。

Protected methods

void attachBaseContext(Context newBase)

为此ContextWrapper设置基本上下文。

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

setTheme(int)getTheme()调用以将主题资源应用于当前主题对象。

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

创建一个没有主题且没有基础上下文的新上下文包装器。

注意:在调用新构建的上下文封装器上的任何其他方法之前, 必须使用 attachBaseContext(Context)来附加基本上下文。

ContextThemeWrapper

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

用指定的主题创建一个新的上下文包装器。

指定的主题将应用于基本上下文的主题之上。 themeResId标识的主题中未明确定义的任何属性都将保留其原始值。

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

用指定的主题创建一个新的上下文包装器。

ContextThemeWrapper(Context, int)不同,传递给此构造函数的主题将完全替代基本上下文的主题。

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
void applyOverrideConfiguration (Configuration overrideConfiguration)

调用以在此上下文中设置“覆盖配置” - 这是一种回复应用于上下文的标准配置的一个或多个值的配置。 有关更多信息,请参阅createConfigurationContext(Configuration)

此方法只能调用一次,并且必须在调用 getResources()getAssets()之前调用。

Parameters
overrideConfiguration Configuration

getAssets

Added in API level 1
AssetManager getAssets ()

返回应用程序包的AssetManager实例。

注意:此方法的实现应该返回一个AssetManager实例,该实例与getResources()返回的Resources实例一致。 例如,他们应该共享相同的Configuration对象。

Returns
AssetManager an AssetManager instance for the application's package

getResources

Added in API level 1
Resources getResources ()

返回应用程序包的资源实例。

注意:此方法的实现应返回一个与getAssets()返回的AssetManager实例一致的资源实例。 例如,他们应该共享相同的Configuration对象。

Returns
Resources a Resources instance for the application's package

getSystemService

Added in API level 1
Object getSystemService (String name)

按名称将句柄返回到系统级服务。 返回的对象的类因所请求的名称而异。 目前可用的名称是:

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.
HARDWARE_PROPERTIES_SERVICE ("hardware_properties")
A HardwarePropertiesManager for accessing hardware properties.

注意:通过此API获取的系统服务可能与它们从中获取的上下文紧密相关。 一般来说,不要在各种不同的上下文(活动,应用程序,服务,提供者等)之间共享服务对象,

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

返回与此上下文关联的主题对象。

Returns
Resources.Theme

setTheme

Added in API level 1
void setTheme (int resid)

为此上下文设置基本主题。 请注意,应在上下文中实例化任何视图之前调用setContentView(View) (例如,在调用setContentView(View)inflate(int, ViewGroup)之前)。

Parameters
resid int: The style resource describing the theme.

Protected methods

attachBaseContext

Added in API level 1
void attachBaseContext (Context newBase)

为此ContextWrapper设置基本上下文。 所有的调用都会被委托给基础上下文。 如果已经设置了基本上下文,则引发IllegalStateException。

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)

setTheme(int)getTheme()调用以将主题资源应用于当前主题对象。 可能会被覆盖以更改默认(简单)行为。 此方法不会在多个线程中同时调用。

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

Hooray!