Context.RegisterComponentCallbacks(IComponentCallbacks) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在 Context 的基礎應用程式中新增 ComponentCallbacks 一個新應用程式,該應用程式會與 ComponentCallbacks 活動及其他元件方法的呼叫同時被呼叫。
[Android.Runtime.Register("registerComponentCallbacks", "(Landroid/content/ComponentCallbacks;)V", "GetRegisterComponentCallbacks_Landroid_content_ComponentCallbacks_Handler")]
public virtual void RegisterComponentCallbacks(Android.Content.IComponentCallbacks? callback);
[<Android.Runtime.Register("registerComponentCallbacks", "(Landroid/content/ComponentCallbacks;)V", "GetRegisterComponentCallbacks_Landroid_content_ComponentCallbacks_Handler")>]
abstract member RegisterComponentCallbacks : Android.Content.IComponentCallbacks -> unit
override this.RegisterComponentCallbacks : Android.Content.IComponentCallbacks -> unit
參數
- callback
- IComponentCallbacks
通話介面。 這可以是介面 ComponentCallbacks 或 ComponentCallbacks2 介面。
- 屬性
備註
在 Context 的基礎應用程式中新增 ComponentCallbacks 一個新應用程式,該應用程式會與 ComponentCallbacks 活動及其他元件方法的呼叫同時被呼叫。 請注意,你<>必須</確保未來適當時機使用#unregisterComponentCallbacks;>這不會為你移除。
之後 Build.VERSION_CODES#S,註冊透過視窗上下文建立 #createWindowContext(int, Bundle) 的 ComponentCallbacks #createWindowContext(Display, int, Bundle)ComponentCallbacks#onConfigurationChanged(Configuration) 至 Context,而非其基礎應用程式。 如果你想處理與視窗情境相關的 UI 元件,當視窗情境有設定變更時,這會很有幫助。
在 Build.VERSION_CODES#TIRAMISU之後,註冊 ComponentCallbacks 到 Activity context 時,會接收 ComponentCallbacks#onConfigurationChanged(Configuration) 來自 Activity#onConfigurationChanged(Configuration) 而不是其基礎應用程式。
之後 Build.VERSION_CODES#UPSIDE_DOWN_CAKE,註冊 的 android.inputmethodservice.InputMethodService ComponentCallbacks 將來自 ComponentCallbacks#onConfigurationChanged(Configuration) InputmethodService,而非其基礎應用程式。 如果你想處理 IME 有設定變更時的 UI 元件,這會很有幫助。
Java 文件 android.content.Context.registerComponentCallbacks(android.content.ComponentCallbacks)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。