如何突出显示搜索词

时间:2012-05-13 09:17:47

标签: android listview search-engine highlight

我正在创建一个像android中的应用程序一样的搜索引擎,我想知道如何在列表视图中突出显示搜索到的单词,就像在此链接中一样。http://androidbible.blogspot.com/2010/12/color-highlight-and-whole-word-search.html提前感谢那些想要帮助的人。

1 个答案:

答案 0 :(得分:3)

我想你可以尝试SpannableString

下面是一个演示。

    TextView tv = (TextView) findViewById(R.id.textView1);
    SpannableString str = new SpannableString("hello");
    BackgroundColorSpan span = new BackgroundColorSpan(Color.YELLOW);
    str.setSpan(span, 0, 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    tv.setText(str);
相关问题