Home > Blockchain >  How to create a custom textview?
How to create a custom textview?

Time:11-30

I want to achieve a view like the one showing in the image below by xml android,

Custom Text view

How can I make this can anyone help, note this can't be single string, it must be two different strings.

Thank you.

CodePudding user response:

You can use Spannable to modify text appearance of a string. Here's how you can do it.

    val boldString = "Geraland Thomas:"
    val regularString = "Lorem ipsum is a placeholder text used in the print and publishing"

    val spannableString = SpannableStringBuilder(boldString   regularString)
    spannableString.setSpan(
        StyleSpan(Typeface.BOLD),
        0,
        boldString.length,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
    )

    val textView: TextView = findViewById(R.id.textview)
    textView.text = spannableString

Check out this great article if you want more customization Spantastic text styling with Spans

  • Related