Context.CreateWindowContext メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
CreateWindowContext(Int32, Bundle) |
非アクティビティ ウィンドウのコンテキストを作成します。 |
CreateWindowContext(Display, Int32, Bundle) |
|
CreateWindowContext(Int32, Bundle)
非アクティビティ ウィンドウのコンテキストを作成します。
[Android.Runtime.Register("createWindowContext", "(ILandroid/os/Bundle;)Landroid/content/Context;", "GetCreateWindowContext_ILandroid_os_Bundle_Handler", ApiSince=30)]
public virtual Android.Content.Context CreateWindowContext (int type, Android.OS.Bundle? options);
[<Android.Runtime.Register("createWindowContext", "(ILandroid/os/Bundle;)Landroid/content/Context;", "GetCreateWindowContext_ILandroid_os_Bundle_Handler", ApiSince=30)>]
abstract member CreateWindowContext : int * Android.OS.Bundle -> Android.Content.Context
override this.CreateWindowContext : int * Android.OS.Bundle -> Android.Content.Context
パラメーター
- type
- Int32
ウィンドウの種類 WindowManager.LayoutParams
- options
- Bundle
ウィンドウ関連のオプションを渡すために使用されるバンドル
戻り値
Context
ウィンドウ以外android.app.Activity activity
の作成に使用できる 。
- 属性
注釈
非アクティビティ ウィンドウのコンテキストを作成します。
ウィンドウ コンテキストは、 などの android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
非アクティビティ ウィンドウを追加するために使用できるコンテキストです。 ウィンドウ コンテキストは、 や で作成されたコンテキストなどandroid.app.Activity Activity
、関連付けられた Display
コンテキストから作成する#createDisplayContext(Display)
必要があります。
ウィンドウ コンテキストは、使用して作成されたウィンドウが占有できるディスプレイの領域に適Configuration
した を使用して作成されます。適切な Resources
で拡張できるように、ビューの場合android.view.LayoutInflater inflating
に使用する必要があります。
次に示すのは、b>がプライマリ ディスプレイにアプリケーション オーバーレイ ウィンドウを追加する<サンプル コードです:</b>
...
final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
final Context windowContext = anyContext.createDisplayContext(primaryDisplay)
.createWindowContext(TYPE_APPLICATION_OVERLAY, null);
final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null);
// WindowManager.LayoutParams initialization
...
// The types used in addView and createWindowContext must match.
mParams.type = TYPE_APPLICATION_OVERLAY;
...
windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
このコンテキストの構成とリソースは、指定された種類のウィンドウが追加されるディスプレイの領域に調整されます。 <b>同じコンテキストに関連付けられているすべてのウィンドウはアフィニティを持ち、ディスプレイ上の異なるディスプレイまたは領域間でのみ一緒に移動できることに注意してください。</b> 異なるウィンドウの種類または関連付けられていないウィンドウを追加する必要がある場合は、個別のコンテキストを使用する必要があります。
ウィンドウ コンテキストの作成はコストの高い操作です。 この API を誤用すると、パフォーマンスが大幅に低下する可能性があります。 ベスト プラクティスは、可能な場合は同じウィンドウ コンテキストを使用することです。 アプローチは、特定のウィンドウの種類を持つ 1 つのウィンドウ コンテキストを作成し、必要な場所に表示して使用することです。
の後Build.VERSION_CODES#S
に、ウィンドウ コンテキストは、 で渡された WindowManager#addView(View, LayoutParams)
の をオーバーライドすることで、既存のトークンのandroid.view.WindowManager.LayoutParams
構成変更をandroid.view.WindowManager.LayoutParams#token token
受け取る機能を提供します。 これは、アプリケーションがウィンドウ トークン共有ユース ケースの既存のアクティビティにウィンドウをアタッチする必要がある場合に便利です。
のウィンドウ コンテキスト Build.VERSION_CODES#R
には、この機能がなかったことに注意してください。 これは、 のウィンドウ コンテキスト Build.VERSION_CODES#R
の操作なしです。
次に示すのは、既存のトークンをウィンドウ コンテキストに <アタッチする b>のサンプル コードです:</b>
final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
final Context windowContext = anyContext.createWindowContext(primaryDisplay,
TYPE_APPLICATION, null);
// Get an existing token.
final IBinder existingToken = activity.getWindow().getAttributes().token;
// The types used in addView() and createWindowContext() must match.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(TYPE_APPLICATION);
params.token = existingToken;
// After WindowManager#addView(), the server side will extract the provided token from
// LayoutParams#token (existingToken in the sample code), and switch to propagate
// configuration changes from the node associated with the provided token.
windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
の後Build.VERSION_CODES#S
に、ウィンドウ コンテキストは を呼び出#registerComponentCallbacks(ComponentCallbacks)
して変更をConfiguration
リッスンする機能を提供しますが、他の種類の Context
は に#getApplicationContext() its Application context
登録ComponentCallbacks
します。 ウィンドウ コンテキストはコールバックのみを伝達 ComponentCallbacks#onConfigurationChanged(Configuration)
することに注意してください。 ComponentCallbacks#onLowMemory()
またはその他の ComponentCallbacks2
コールバックは呼び出されません。
UI 関連のクエリに または android.app.Service
コンテキストを使用android.app.Application
すると、可変の画面サイズ (折りたたみ式など) を持つデバイスやマルチウィンドウ モードで、レイアウトまたは継続性の問題が発生する可能性があることに注意してください。これらの非 UI コンテキストでは、ビジュアル コンテナーの変更が反映Configuration
されない可能性があるためです。
の Java ドキュメント android.content.Context.createWindowContext(int, android.os.Bundle)
。
このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。
適用対象
CreateWindowContext(Display, Int32, Bundle)
Context
指定Display
した に非android.app.Activity activity
ウィンドウの を作成します。
[Android.Runtime.Register("createWindowContext", "(Landroid/view/Display;ILandroid/os/Bundle;)Landroid/content/Context;", "GetCreateWindowContext_Landroid_view_Display_ILandroid_os_Bundle_Handler", ApiSince=31)]
public virtual Android.Content.Context CreateWindowContext (Android.Views.Display display, int type, Android.OS.Bundle? options);
[<Android.Runtime.Register("createWindowContext", "(Landroid/view/Display;ILandroid/os/Bundle;)Landroid/content/Context;", "GetCreateWindowContext_Landroid_view_Display_ILandroid_os_Bundle_Handler", ApiSince=31)>]
abstract member CreateWindowContext : Android.Views.Display * int * Android.OS.Bundle -> Android.Content.Context
override this.CreateWindowContext : Android.Views.Display * int * Android.OS.Bundle -> Android.Content.Context
パラメーター
- display
- Display
Display
関連付ける
- type
- Int32
ウィンドウの種類 WindowManager.LayoutParams
- options
- Bundle
ウィンドウ関連のオプションを渡すために使用されるバンドル。
戻り値
Context
ウィンドウ以外android.app.Activity activity
の作成に使用できる 。
- 属性
注釈
Context
指定Display
した に非android.app.Activity activity
ウィンドウの を作成します。
と #createWindowContext(int, Bundle)
同様ですが、 display
は暗黙的に を使用 #getDisplay() original Context's Display
するのではなく、 に渡されます。
このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。