Context.CreateWindowContext 메서드

정의

오버로드

CreateWindowContext(Int32, Bundle)

비활성 창에 대한 컨텍스트를 만듭니다.

CreateWindowContext(Display, Int32, Bundle)

Context 지정된 Display에 비 창android.app.Activity activity에 대한 을 만듭니다.

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 으로 만들어집니다. 보기를 적절한 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를 잘못 사용하면 성능이 크게 떨어질 수 있습니다. 가능한 경우 동일한 창 컨텍스트를 사용하는 것이 가장 좋습니다. 접근 방식은 특정 창 유형을 사용하여 하나의 창 컨텍스트를 만들고 필요한 모든 곳에서 표시하고 사용하는 것입니다.

이후에 Build.VERSION_CODES#S창 컨텍스트는 에 전달된 WindowManager#addView(View, LayoutParams)의 를 재정의 android.view.WindowManager.LayoutParams 하여 기존 토큰에 대한 구성 변경 내용을 수신하는 android.view.WindowManager.LayoutParams#token token 기능을 제공합니다. 이는 애플리케이션이 창 토큰 공유 사용 사례에 대한 기존 활동에 창을 연결해야 하는 경우에 유용합니다.

의 창 컨텍스트에는 Build.VERSION_CODES#R 이 기능이 없습니다. 의 창 컨텍스트에 대한 no-op입니다 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 는 를 에 등록 ComponentCallbacks#getApplicationContext() its Application context합니다. 창 컨텍스트는 콜백만 전파합니다 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대신 에 전달됩니다.

에 대한 Java 설명서입니다 android.content.Context.createWindowContext(android.view.Display, int, android.os.Bundle).

이 페이지의 일부는 만들고 공유하며 에 설명된 용어에 따라 사용되는 작업을 기반으로 수정됩니다.

적용 대상