本文介紹了Android - 從 EditText 中選擇文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試實現(xiàn)復(fù)制/粘貼功能.如何從 EditText 中選擇文本?
I'm trying to implement a copy/paste function. How can I get a selection of text from an EditText?
EditText et=(EditText)findViewById(R.id.title);
blabla onclicklistener on a button:
blabla onclicklistener on a button:
int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();
那我就卡住了.有什么想法嗎?
Then I'm stuck. Any ideas?
推薦答案
看起來你已經(jīng)完成了找到所選區(qū)域的困難部分.現(xiàn)在你只需要從全文中提取那個子字符串.
Seems like you've already done the hard part by finding what the selected area is. Now you just need to pull that substring out of the full text.
試試這個:
String selectedText = et.getText().substring(startSelection, endSelection);
這只是一個基本的 Java 字符串 操作.
It's just a basic Java String operation.
這篇關(guān)于Android - 從 EditText 中選擇文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!