Highlighting Text Color using Html.fromHtml() in Android?

后端 未结 9 1331
忘了有多久
忘了有多久 2020-11-28 19:26

I am developing an application in which there will be a search screen where user can search for specific keywords and that keyword should be highlighted. I have found Html.f

9条回答
  •  遥遥无期
    2020-11-28 20:07

    First Convert your string into HTML then convert it into spannable. do as suggest the following codes.

     Spannable spannable = new SpannableString(Html.fromHtml(labelText));
                        
    spannable.setSpan(new ForegroundColorSpan(Color.parseColor(color)), spannable.toString().indexOf("•"), spannable.toString().lastIndexOf("•") + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                
    

提交回复
热议问题