言語

Context.CreateWindowContext メソッド

定義

オーバーロード

名前 説明
CreateWindowContext(Int32, Bundle)

非アクティビティ ウィンドウのコンテキストを作成します。

CreateWindowContext(Display, Int32, Bundle)

指定したContextandroid.app.Activity activity以外のウィンドウのDisplayを作成します。

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などの非アクティビティ ウィンドウを追加するために使用できるコンテキストです。 ウィンドウ コンテキストは、関連付けられた Displayを持つコンテキスト ( android.app.Activity Activity#createDisplayContext(Display)で作成されたコンテキストなど) から作成する必要があります。

ウィンドウ コンテキストは、ウィンドウで作成されたウィンドウが占有できるディスプレイ領域の適切な Configuration を使用して作成されます。ビューを android.view.LayoutInflater inflating する場合は、適切な Resourcesで膨らませることができるように使用する必要があります。

プライマリ ディスプレイにアプリケーション オーバーレイ ウィンドウを<>追加するサンプル コードを次に示します:</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後、ウィンドウ コンテキストは、android.view.WindowManager.LayoutParams#token tokenで渡されたandroid.view.WindowManager.LayoutParamsWindowManager#addView(View, LayoutParams)をオーバーライドすることによって、既存のトークンの構成変更を受け取る機能を提供します。 これは、アプリケーションがウィンドウ トークン共有のユース ケースの既存のアクティビティにウィンドウをアタッチする必要がある場合に便利です。

Build.VERSION_CODES#Rのウィンドウ コンテキストには、この機能がなかったことに注意してください。 これは、 Build.VERSION_CODES#Rのウィンドウ コンテキストの no-op です。

既存のトークンをウィンドウ コンテキストに<>アタッチするサンプル コードを次に示します:</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した後、ウィンドウ コンテキストは、Configurationを呼び出すことによって#registerComponentCallbacks(ComponentCallbacks)の変更をリッスンする機能を提供しますが、他の種類のContextComponentCallbacks#getApplicationContext() its Application contextを登録します。 ウィンドウ コンテキストはコールバック ComponentCallbacks#onConfigurationChanged(Configuration) 伝達のみであることに注意してください。 ComponentCallbacks#onLowMemory() または ComponentCallbacks2 内の他のコールバックは呼び出されません。

UI 関連のクエリに android.app.Application または android.app.Service コンテキストを使用すると、画面サイズが可変のデバイス (折りたたみ式など) またはマルチウィンドウ モードでのレイアウトまたは継続性の問題が発生する可能性があることに注意してください。これらの非 UI コンテキストは、ビジュアル コンテナーの Configuration の変更を反映していない可能性があるためです。

Javaドキュメント。

このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。

適用対象

CreateWindowContext(Display, Int32, Bundle)

指定したContextandroid.app.Activity activity以外のウィンドウのDisplayを作成します。

[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

属性

注釈

指定したContextandroid.app.Activity activity以外のウィンドウのDisplayを作成します。

#createWindowContext(int, Bundle)と同様ですが、displayを暗黙的に使用するのではなく、#getDisplay() original Context's Displayが渡されます。

Javaドキュメント。

このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。

適用対象