在TextView中选择文本(安卓2.2) [英] Selecting text on TextView (android 2.2)
问题描述
如何实现在Android 2.2中选择文本的能力?我搜索谷歌,但不能找到一个解决方案。
How to implement selecting text capability on Android 2.2? I searched Google but can't find a solution.
推荐答案
这是我发现(从谷歌)的唯一途径,以支持它为Android 1.6+,它的工作原理,但它并不理想,我认为股票的android你不能按住一个web视图突出到V2.3,但我可能是错了。
This is the only way I've found (from google) to support it for android 1.6+, it works but it's not ideal, I think in stock android you can't hold down a webview to highlight until v2.3, but I may be mistaken..
到这是一个web视图的方式,它也可能在工作TextView的,但我还没有尝试过
By the way this is for a webview, it might also work on textview, but I haven't tried it
(注:这是目前我什么运的应用程序是使用,所以它适用于所有我已经受够了测试,在手机上,但我发现这个问题的唯一原因是因为我正在寻找,并希望有人来了与现在更好的方法)
(Note: this is currently what my shipped app is using, so it works with all the phones I've had it tested on, but the only reason I found this question was because I was searching and hoping that someone had come up with a better way by now)
我刚刚拿到了所谓的选择文本,它调用函数selectnCopy()菜单项
I've just got a menu item called "Select text" which calls the function "selectnCopy()"
@Override
public boolean onOptionsItemSelected(MenuItem item) {
//..
switch (item.getItemId()) {
case R.id.menu_select:
selectnCopy();
return true;
//..
}
}
看起来像这样:
Which looks like this:
public void selectnCopy() {
Toast.makeText(WebClass.this,getString(R.string.select_help),Toast.LENGTH_SHORT).show();
try {
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(wv);
} catch (Exception e) {
throw new AssertionError(e);
}
}
的通知我已经把select_help串那里举杯,这只是因为它不是立即清楚用户如何它应该工作
Notice I've put the select_help string there as a toast, that's just because it's not immediately clear to the user how it's supposed to work
<string name="select_help">Touch and drag to copy text.</string>
这篇关于在TextView中选择文本(安卓2.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!