IViewTranslationCallback.OnShowTranslation(View) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當翻譯後的文字準備好顯示,或使用者在隱藏後請求重新顯示翻譯內容時,會呼叫它。
[Android.Runtime.Register("onShowTranslation", "(Landroid/view/View;)Z", "GetOnShowTranslation_Landroid_view_View_Handler:Android.Views.Translation.IViewTranslationCallbackInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=31)]
public bool OnShowTranslation(Android.Views.View view);
[<Android.Runtime.Register("onShowTranslation", "(Landroid/view/View;)Z", "GetOnShowTranslation_Landroid_view_View_Handler:Android.Views.Translation.IViewTranslationCallbackInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=31)>]
abstract member OnShowTranslation : Android.Views.View -> bool
參數
- view
- View
顯示翻譯內容的視圖。
傳回
true 如果 View 能顯示翻譯。
- 屬性
備註
當翻譯後的文字準備好顯示,或使用者在隱藏後請求重新顯示翻譯內容時,會呼叫它。
翻譯後的內容可從 View#getViewTranslationResponse取得。 此方法不會在 或 View#onViewTranslationResponse之前View#onVirtualViewTranslationResponses被調用。
注意:使用者可能會更改文字,導致新的 ViewTranslationResponse 報稅表顯示新的翻譯。 如果你快取了這裡 ViewTranslationResponse ,記得要保持快取值是最新的。
注意:對於 TextView 實作, ContentCaptureSession#notifyViewTextChanged 不應該用翻譯後的文字來呼叫,只要在這裡呼叫 setText() 即可觸發該方法。 你應該選擇覆蓋 View#onProvideContentCaptureStructure() 原文而非翻譯文本,或使用其他方式顯示翻譯後的文字。
注意:在 Android 版本 android.os.Build.VERSION_CODES#TIRAMISU 及之後版本中,實作必須能處理可選取 android.widget.TextView 的(即 android.widget.TextView#isTextSelectable() 返回 true. TextView 預設的回調實作會使用 a android.text.method.TransformationMethod 來顯示已翻譯的文字,當選擇翻譯後的文字時,會導致當機。 因此,預設回調會暫時使 TextView 無法選擇,同時顯示翻譯文字。 這是處理可選文本觀點的一種方法,即使用轉換方法。
請參考 View#onViewTranslationResponse 如何取得翻譯後的資訊。
Java 文件 android.view.translation.ViewTranslationCallback.onShowTranslation(android.view.View)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。