Freigeben über


EditorInfo.GetInitialSurroundingText(Int32, Int32, Int32) Method

Definition

Gets the surrounding text around the current cursor, with <var>beforeLength</var> characters of text before the cursor (start of the selection), <var>afterLength</var> characters of text after the cursor (end of the selection), and all of the selected text.

[Android.Runtime.Register("getInitialSurroundingText", "(III)Landroid/view/inputmethod/SurroundingText;", "GetGetInitialSurroundingText_IIIHandler", ApiSince=31)]
public virtual Android.Views.InputMethods.SurroundingText? GetInitialSurroundingText (int beforeLength, int afterLength, int flags);
[<Android.Runtime.Register("getInitialSurroundingText", "(III)Landroid/view/inputmethod/SurroundingText;", "GetGetInitialSurroundingText_IIIHandler", ApiSince=31)>]
abstract member GetInitialSurroundingText : int * int * int -> Android.Views.InputMethods.SurroundingText
override this.GetInitialSurroundingText : int * int * int -> Android.Views.InputMethods.SurroundingText

Parameters

beforeLength
Int32

The expected length of the text before the cursor.

afterLength
Int32

The expected length of the text after the cursor.

flags
Int32

Supplies additional options controlling how the text is returned. May be either 0 or InputConnection#GET_TEXT_WITH_STYLES.

Returns

an android.view.inputmethod.SurroundingText object describing the surrounding text and state of selection, or null if the editor or system could not support this protocol.

Attributes

Remarks

Gets the surrounding text around the current cursor, with <var>beforeLength</var> characters of text before the cursor (start of the selection), <var>afterLength</var> characters of text after the cursor (end of the selection), and all of the selected text.

The initial surrounding text for return could be trimmed if oversize. Fundamental trimming rules are:

<ul> <li>The text before the cursor is the most important information to IMEs.</li> <li>The text after the cursor is the second important information to IMEs.</li> <li>The selected text is the least important information but it shall NEVER be truncated. When it is too long, just drop it.</li> </ul>

For example, the subText can be viewed as TextBeforeCursor + Selection + TextAfterCursor. The result could be:

<ol> <li>(maybeTrimmedAtHead)TextBeforeCursor + Selection + TextAfterCursor(maybeTrimmedAtTail)</li> <li>(maybeTrimmedAtHead)TextBeforeCursor + TextAfterCursor(maybeTrimmedAtTail)</li> </ol>

Java documentation for android.view.inputmethod.EditorInfo.getInitialSurroundingText(int, int, int).

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