IInputConnectionExtensions.SetComposingText 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| SetComposingText(IInputConnection, String, Int32) |
將目前正在合成的文字替換成給定的文字,並設定新的游標位置。 |
| SetComposingText(IInputConnection, String, Int32, TextAttribute) |
setComposingText(CharSequence,int) 的變體。 |
SetComposingText(IInputConnection, String, Int32)
將目前正在合成的文字替換成給定的文字,並設定新的游標位置。
public static bool SetComposingText(this Android.Views.InputMethods.IInputConnection self, string? text, int newCursorPosition);
static member SetComposingText : Android.Views.InputMethods.IInputConnection * string * int -> bool
參數
- self
- IInputConnection
要呼叫該方法的輸入連線。
- text
- String
寫作文本。 使用預設的文字寫作風格。
- newCursorPosition
- Int32
文字周圍的新游標位置。 若 > 0,則相對於文本結尾為 - 1;若 <= 0,則相對於文本開頭。 所以值為 1 時,你總是會跳到插入全文之後的位置。 請注意,這表示你無法將游標置於文字中,因為編輯器可能會修改你提供的文字,導致無法正確指定該位置。
傳回
成功時為真;若輸入連線不再有效,則為假。
備註
將目前正在合成的文字替換成給定的文字,並設定新的游標位置。 任何先前設定的寫作文本都會自動移除。
如果目前有任何正在進行的寫作時段,所有包含該時段的字元都會被移除。 將傳過的文字加入原有內容,並在此文本中加入一個寫作跨度。 若沒有啟用的組合區間,則將傳遞的文字加入游標位置(若有選中的字元,先移除),並在新文字上加入一個組合區間。 最後,游標會被移動到 newCursorPosition 指定的位置。
IME 通常會呼叫這個方法,用來在創作期間新增、刪除或更改字元。 呼叫此方法會在批次輸入結束後,編輯器在目前 IME 上呼叫 InputMethodService.onUpdateSelection(int, int, int, int, int, int)。
編輯作者:請注意,文字可能與寫作時間內的內容非常相似,甚至完全不同,甚至根本沒有寫作時間。 請注意,雖然這不是一般用途,但弦線可能已經是空的。 請正常處理,將當前正在寫的文字替換成空字串。 另外,要小心游標的位置。 以我個人經驗來說,這完全依賴上述描述的運作。 由於這會改變編輯器的內容,您需要透過呼叫 InputMethodManager.updateSelection(android.view.View,int,int,int,int,int)來將變更告知輸入法,但若批次編輯正在進行中,請小心等待完成。 請注意,這個方法可以將游標位置設在構圖文本的任一邊緣或完全在邊緣之外,但 IME 也可能在後續呼叫中將游標位置移到合成文本內部,因此你完全不必假設:構圖文本與選取區完全獨立。
Android 參考資料。android.view.inputmethod.InputConnection.setComposingText
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
適用於
SetComposingText(IInputConnection, String, Int32, TextAttribute)
setComposingText(CharSequence,int) 的變體。
public static bool SetComposingText(this Android.Views.InputMethods.IInputConnection self, string text, int newCursorPosition, Android.Views.InputMethods.TextAttribute? textAttribute);
static member SetComposingText : Android.Views.InputMethods.IInputConnection * string * int * Android.Views.InputMethods.TextAttribute -> bool
參數
- self
- IInputConnection
要呼叫該方法的輸入連線。
- text
- String
寫作文本。 使用預設的文字寫作風格。 這個值不可能為零值。
- newCursorPosition
- Int32
文字周圍的新游標位置。 若 > 0,則相對於文本結尾為 - 1;若 <= 0,則相對於文本開頭。 所以值為 1 時,你總是會跳到插入全文之後的位置。 請注意,這表示你無法將游標置於文字中,因為編輯器可能會修改你提供的文字,導致無法正確指定該位置。
- textAttribute
- TextAttribute
關於文本的額外資訊。 這個值可能是 Null。
傳回
成功時為真;若輸入連線不再有效,則為假。
備註
setComposingText(CharSequence,int) 的變體。 此方法用於讓 IME 在撰寫文本時提供額外資訊。
Android 參考資料。android.view.inputmethod.InputConnection.setComposingText
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。