how to have bold and normal text in same textview in android?

前端 未结 7 1185
终归单人心
终归单人心 2021-02-18 23:48

I have searched internet and tried the following code but its not working

SpannableString ss1 = new SpannableString(\"Health: \");
           ss1.setSpan(new and         


        
7条回答
  •  终归单人心
    2021-02-19 00:20


    Below I have mentioned the code which one through you can create spannableString in Kotlin

    val spannableStringBuilder = SpannableStringBuilder()
    
    val boldSpan: StyleSpan = StyleSpan(Typeface.BOLD)
    
    sp_text.setSpan(boldSpan, firstIndex, lastIndex,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
    
    sp_text.setSpan(clickableSpan, firstIndex, lastIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
                sp_text.setSpan(ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.colorPrimary)), firstIndex, lastIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
    

提交回复
热议问题