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

后端 未结 9 1333
忘了有多久
忘了有多久 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:19

     String name = modelOrderList.get(position).getName();   //get name from List
        String text = "" + name + ""; //set Black color of name
        /* check API version, according to version call method of Html class  */
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) {
            Log.d(TAG, "onBindViewHolder: if");
            holder.textViewName.setText(context.getString(R.string._5687982) + " ");
            holder.textViewName.append(Html.fromHtml(text));
        } else {
            Log.d(TAG, "onBindViewHolder: else");
            holder.textViewName.setText("123456" + " ");   //set text 
            holder.textViewName.append(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY));   //append text into textView
        }
    

提交回复
热议问题