我有一个我想要的 android 应用程序:每当用户从编辑文本中按下复制时,任何事件都会发生,它是任何编辑文本,例如来自信使编辑文本,邮件编辑文本任何一个,当用户按下复制文本时,我想发生任何事件,所以任何人都给我这个例子吗?我不知道,所以请帮助我,在此先感谢.
I have one android apps in that i want : whenever user press copy from the edittext,any event occure, it any of edittext like from messenger edittext,mail edittext any one,when user press copy text, i want to occure any event,so any body give me example for this ?i have no idea about it,so please help me, thanks in advance.
我得到了解决方案:我创建了一项服务:在 oncreate 中:
I got solutions: I create one service : on that in oncreate :
ClipboardManager clipBoard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipBoard.addPrimaryClipChangedListener(new ClipboardListener());
并添加服务:
class ClipboardListener implements
ClipboardManager.OnPrimaryClipChangedListener {
public void onPrimaryClipChanged() {
ClipboardManager clipBoard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
CharSequence pasteData = "";
ClipData.Item item = clipBoard.getPrimaryClip().getItemAt(0);
pasteData = item.getText();
Toast.makeText(getApplicationContext(), "copied val=" + pasteData,
Toast.LENGTH_SHORT).show();
}
}
这篇关于Android如何在android中检测Edittext的Copy事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!