共用方式為


IInputConnection.DeleteSurroundingText(Int32, Int32) Method

Definition

Delete <var>beforeLength</var> characters of text before the current cursor position, and delete <var>afterLength</var> characters of text after the current cursor position, excluding the selection.

[Android.Runtime.Register("deleteSurroundingText", "(II)Z", "GetDeleteSurroundingText_IIHandler:Android.Views.InputMethods.IInputConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public bool DeleteSurroundingText (int beforeLength, int afterLength);
[<Android.Runtime.Register("deleteSurroundingText", "(II)Z", "GetDeleteSurroundingText_IIHandler:Android.Views.InputMethods.IInputConnectionInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member DeleteSurroundingText : int * int -> bool

Parameters

beforeLength
Int32

The number of characters before the cursor to be deleted, in code unit. If this is greater than the number of existing characters between the beginning of the text and the cursor, then this method does not fail but deletes all the characters in that range.

afterLength
Int32

The number of characters after the cursor to be deleted, in code unit. If this is greater than the number of existing characters between the cursor and the end of the text, then this method does not fail but deletes all the characters in that range.

Returns

true on success, false if the input connection is no longer valid.

Attributes

Remarks

Delete <var>beforeLength</var> characters of text before the current cursor position, and delete <var>afterLength</var> characters of text after the current cursor position, excluding the selection. Before and after refer to the order of the characters in the string, not to their visual representation: this means you don't have to figure out the direction of the text and can just use the indices as-is.

The lengths are supplied in Java chars, not in code points or in glyphs.

Since this method only operates on text before and after the selection, it can't affect the contents of the selection. This may affect the composing span if the span includes characters that are to be deleted, but otherwise will not change it. If some characters in the composing span are deleted, the composing span will persist but get shortened by however many chars inside it have been removed.

<strong>IME authors:</strong> please be careful not to delete only half of a surrogate pair. Also take care not to delete more characters than are in the editor, as that may have ill effects on the application. Calling this method will cause the editor to call android.inputmethodservice.InputMethodService#onUpdateSelection(int, int, int, int, int, int) on your service after the batch input is over.

<strong>Editor authors:</strong> please be careful of race conditions in implementing this call. An IME can make a change to the text or change the selection position and use this method right away; you need to make sure the effects are consistent with the results of the latest edits. Also, although the IME should not send lengths bigger than the contents of the string, you should check the values for overflows and trim the indices to the size of the contents to avoid crashes. Since this changes the contents of the editor, you need to make the changes known to the input method by calling InputMethodManager#updateSelection(View, int, int, int, int), but be careful to wait until the batch edit is over if one is in progress.

Java documentation for android.view.inputmethod.InputConnection.deleteSurroundingText(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