我想在我的 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模板网!
android EditText 融入背景android EditText blends into background(android EditText 融入背景)
更改 EditText 的线条颜色 - AndroidChange Line Color of EditText - Android(更改 EditText 的线条颜色 - Android)
EditText 始终显示带 2 位小数的数字EditText showing numbers with 2 decimals at all times(EditText 始终显示带 2 位小数的数字)
更改光标在展开的 EditText 中的开始位置Changing where cursor starts in an expanded EditText(更改光标在展开的 EditText 中的开始位置)
android中的EditText,adjustPan,ScrollView问题EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView问题)
自动调整 EditTextAutosizing EditText(自动调整 EditText)