语言

Context.IsUiContext 属性

定义

如果 true 上下文是可访问 UI 组件的 WindowManagerUI 上下文, android.view.LayoutInflater LayoutInflater 则 android.app.WallpaperManager WallpaperManager返回或 。

public virtual bool IsUiContext { [Android.Runtime.Register("isUiContext", "()Z", "GetIsUiContextHandler", ApiSince=31)] get; }
[<get: Android.Runtime.Register("isUiContext", "()Z", "GetIsUiContextHandler", ApiSince=31)>]
member this.IsUiContext : bool

属性值

如果上下文是可以访问 WindowManager、LayoutInflater 或 WallpaperManager 等 UI 组件的 UI 上下文,则返回 true。 如果启用了 StrictMode.VmPolicy.Builder.detectIncorrectContextUse(),则从非 UI 上下文访问 UI 组件将引发冲突。 UI 上下文的示例包括活动、从 createWindowContext(int、Bundle)或 InputMethodService Note 创建的上下文,即使以编程方式允许,也不建议重写此方法以绕过 IncorrectContextUseViolation 验证。

特性

注解

如果 true 上下文是可访问 UI 组件的 WindowManagerUI 上下文, android.view.LayoutInflater LayoutInflater 则 android.app.WallpaperManager WallpaperManager返回或 。 如果已启用,则从非 UI 上下文访问 UI 组件将android.os.strictmode.Violationandroid.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse()引发。

UI 上下文的示例是一个 android.app.Activity Activity、一个从 #createWindowContext(int, Bundle) 或 android.inputmethodservice.InputMethodService InputMethodService

请注意,即使以编程方式允许此方法,也不建议重写此方法以绕过 android.os.strictmode.IncorrectContextUseViolation 验证。

Java文档android.content.Context.isUiContext()。

本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。

适用于