Android - Highlight a Word In a TextView?

后端 未结 9 1791
予麋鹿
予麋鹿 2020-12-07 15:57

I have a database search query which search in the database for a word entered by the user and return a Cursor.

In my ListActivity

9条回答
  •  醉酒成梦
    2020-12-07 16:25

    I haven't done it but this looks promising:

    http://developer.android.com/reference/android/text/SpannableString.html
    http://developer.android.com/guide/topics/resources/string-resource.html
    

    public final void setText (CharSequence text)

    Since: API Level 1 Sets the string value of the TextView. TextView does not accept HTML-like formatting, which you can do with text strings in XML resource files. To style your strings, attach android.text.style.* objects to a SpannableString, or see the Available Resource Types documentation for an example of setting formatted text in the XML resource file.

    http://developer.android.com/reference/android/widget/TextView.html

提交回复
热议问题