Udostępnij za pośrednictwem


IViewTranslationCallback.OnShowTranslation(View) Method

Definition

Called when the translated text is ready to show or if the user has requested to reshow the translated content after hiding it.

[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

Parameters

view
View

Returns

true if the View handles showing the translation.

Attributes

Remarks

Called when the translated text is ready to show or if the user has requested to reshow the translated content after hiding it.

The translated content can be obtained from View#getViewTranslationResponse. This method will not be called before View#onViewTranslationResponse or View#onVirtualViewTranslationResponses.

NOTE: It is possible the user changes text that causes a new ViewTranslationResponse returns to show the new translation. If you cache the ViewTranslationResponse here, you should remember to keep the cached value up to date.

NOTE: For TextView implementation, ContentCaptureSession#notifyViewTextChanged shouldn't be called with the translated text, simply calling setText() here will trigger the method. You should either override View#onProvideContentCaptureStructure() to report the original text instead of the translated text or use a different approach to display the translated text.

NOTE: In Android version android.os.Build.VERSION_CODES#TIRAMISU and later, the implementation must be able to handle a selectable android.widget.TextView (i.e., android.widget.TextView#isTextSelectable() returns true. The default callback implementation for TextView uses a android.text.method.TransformationMethod to show the translated text, which will cause a crash when the translated text is selected. Therefore, the default callback temporarily makes the TextView non-selectable while the translation text is shown. This is one approach for handling selectable TextViews a TransformationMethod is used.

See View#onViewTranslationResponse for how to get the translated information.

Java documentation for android.view.translation.ViewTranslationCallback.onShowTranslation(android.view.View).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to