本文介紹了在android編輯文本中設置光標位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
如何在 android 編輯文本中設置光標位置?我有一個編輯文本,在創建時我想將光標設置為最后一些時間在文本中間的一些時間,我該怎么辦?
How can i set the cursor position in android edit text? I have an edit text and on create i want to set the cursor to some times in the end some times in the middle of the text, what can i do?
我的編輯文字如下:
android:id="@+id/editText11"
android:layout_width="wrap_content"
android:layout_height="200sp"
android:layout_above="@+id/horizontalScrollView1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="top"
android:background="#00000000"
android:inputType="textMultiLine"
android:singleLine="true"
推薦答案
您可以通過以下方式實現:
You can achieve this by using :
Edittext.setSelection(Edittext.length());
這會將光標位置放在最后.否則,您可以獲取字符串中的文本并檢查要放置光標的文本位置并這樣做
this will put the cursor position in the end. otherwise you can get the text in a string and check the text position where you want to put the cursor and do it like this
String text = edittext.getText().toString();
for(int i = 0; i <text.length();i++)
{
//your logic here to check the position of text
}
然后
Edittext.setSelection(position);
這篇關于在android編輯文本中設置光標位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!