語言

IInputConnectionExtensions.ReplaceText 方法

定義

在編輯器中將特定範圍替換成建議文字。

public static bool ReplaceText(this Android.Views.InputMethods.IInputConnection self, int start, int end, string text, int newCursorPosition, Android.Views.InputMethods.TextAttribute? textAttribute);
static member ReplaceText : Android.Views.InputMethods.IInputConnection * int * int * string * int * Android.Views.InputMethods.TextAttribute -> bool

參數

start
Int32

替換應該從哪裡開始的角色索引。 值為 0 或以上

end
Int32

替換應該結束的角色索引。 值為 0 或以上

text
String

要替換的文字。 這可能包括風格。 這個值不可能為零值。

newCursorPosition
Int32

文字周圍的新游標位置。 若 > 0,則相對於文本結尾為 - 1;若 <= 0,則相對於文本開頭。 所以值為 1 時,你總是會跳到插入全文之後的位置。 請注意,這代表你無法將游標置於文字中。

textAttribute
TextAttribute

關於文本的額外資訊。 這個值可能是 Null。

傳回

若替換指令已送達相關編輯器(無論替換是否成功),則為 true;否則為 false。

備註

在編輯器中將特定範圍替換成建議文字。

此方法完成任何正在進行的組合文字,保持文字 as-is,將指定範圍的文字替換為提供的 CharSequence,然後依據 newCursorPosition 移動游標。 這的行為像是呼叫 finishComposingText()、setSelection(start, end),然後 commitText(text, newCursorPosition, textAttribute)。

與 setSelection(int, int) 類似,起始與結束的順序並不重要。 實際上,從頭到尾的區域和從頭到尾的區域是相同的。 編輯作者們,請準備好接受一個比結尾更重要的開頭。

Android 參考資料。android.view.inputmethod.InputConnection.replaceText

本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。

適用於