【问题标题】:show selection pointers and highlight text in textview with longclick使用 longclick 在 textview 中显示选择指针并突出显示文本
【发布时间】:2013-04-21 02:13:51
【问题描述】:

我有一个 TextView,我想在其上实现 LongClickListner 并选择其中的部分文本...但是选择指针没有出现,文本也没有突出显示。 我知道选择了文本,因为当我使用 view.getselectionstart() 和 view.getselectionend() 它们返回正确的值...在我使用的代码下方:

textView.setOnLongClickListener(new OnLongClickListener() {

public boolean onLongClick(View v) {
   Selection.setSelection((Spannable) textView.getText(),5, 10);
   v.setSelected(true);
   return true;
}
 });

这没有显示任何东西.....但是当我尝试记录选择开始和结束时:

Log.d("SELECTED TEXT LISTNER",Selection.getSelectionStart(textView.getText())
+ " " +Selection.getSelectionEnd(textView.getText()));

返回正确的值 (5, 10)...任何帮助我如何显示选择指针并在 longclick 上突出显示??

【问题讨论】:

    标签: android


    【解决方案1】:

    在 XML 中:

    android:textIsSelectable="true"
    

    以编程方式:

    textView.setTextIsSelectable(true);
    

    您无需实现自己的onLongClickListener,因为默认行为如您所述。

    【讨论】:

      猜你喜欢
      • 2015-04-05
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多