本文介紹了在android中剪切、復制、粘貼的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想在我的 EditText 中實現剪切、復制、粘貼功能,我嘗試使用以下代碼:
I want to implement the cut,copy, paste functionality in my EditText,i tried with the following code :
ClipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
editbox1.setText(ClipMan.getText());
用于粘貼文本,但它會將整個文本粘貼到另一個編輯框中..我想復制選定的文本并將該文本粘貼到同一個編輯框中,就像普通記事本一樣..
for paste the text,but it paste the whole text in another Editbox..I want to copy the selected text and paste that text in the same Editbox just like the normal notepad works..
非常感謝任何建議...謝謝!!
Any suggestions are greatly appreciated... Thanks !!
推薦答案
我終于可以復制粘貼到我的應用程序中了..現在我可以使用此代碼僅粘貼選定的文本:
Finally i am able to copy ,paste in my application..now i can paste only selected text by using this code :
Editable s1;
EditText editbox2;
復制選定的文本:
if(editbox2.getSelectionEnd() > editbox2.getSelectionStart())
{
s1 = (Editable) editbox2.getText().subSequence(editbox2.getSelectionStart(), editbox2.getSelectionEnd());
}else
{
s1 = (Editable) editbox2.getText().subSequence(editbox2.getSelectionEnd(), editbox2.getSelectionStart());
}
粘貼選定的文本:
editbox2.getText().replace(Math.min(editbox2.getSelectionStart(),editbox2.getSelectionEnd()), Math.max(editbox2.getSelectionStart(), editbox2.getSelectionEnd()),s1, 0, s1.length());
這篇關于在android中剪切、復制、粘貼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!