显示选择指针和突出显示文本与longclick的TextView [英] show selection pointers and highlight text in textview with longclick
问题描述
我有我想要实现LongClickListner并选择其中的部分文字TextView中......不过选择指针不会出现,文本不突出显示。
我知道文本被选中,因为当我使用view.getselectionstart()和view.getselectionend()它们返回正确的价值观......下面code我使用:
I have a TextView that I want to implement LongClickListner on and select part of the text in it... However selection pointers don't appear and the text is not highlighted. I know the text is selected because when I use view.getselectionstart() and view.getselectionend() they return the right values...below the code I use:
textView.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Selection.setSelection((Spannable) textView.getText(),5, 10);
v.setSelected(true);
return true;
}
});
这不显示任何东西.....但是,当我尝试登录选择开始和结束:
This doesn't show any thing.....But when I try to log selection start and end:
Log.d("SELECTED TEXT LISTNER",Selection.getSelectionStart(textView.getText())
+ " " +Selection.getSelectionEnd(textView.getText()));
正确的价值观(5,10)返回...任何帮助我该怎么让选择指针和突出显示longclick ??
the right values (5, 10) are returned...any help how I can show selection pointers and highlight on longclick??
推荐答案
在XML:
android:textIsSelectable="true"
编程方式:
textView.setTextIsSelectable(true);
您将不再需要实现自己的 onLongClickListener
作为默认行为是像你描述。
You won't need to implement your own onLongClickListener
as the default behaviour is as you described.
这篇关于显示选择指针和突出显示文本与longclick的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!