How to search for a word in a string and highlight word in a text view in android?

前端 未结 3 790
广开言路
广开言路 2020-12-30 12:46

in my android application i have a string that contains a specific word so i want to display whole string in text view and the specific word should be highlighted.Hope follo

3条回答
  •  被撕碎了的回忆
    2020-12-30 13:04

    If I can understand you have the list of words and you want to find this words in text and highlight them so in this answer you have three input parameter:

    1. full text.
    2. yourList
    3. yourTextview to show the result text

      String text = "full of your text";
      Spannable textSpannable = new SpannableString(text);
      
      for (int j =0 ; j

提交回复
热议问题