android-studiotextviewbold

How to make only some Words bold in Text View in XML (Android Studio)?


I was making a text view in XML in Android Studio and wanted to know if there is any way by which we can make only some words bold in it. I know how it can be done programmatically, but is there any way to do it in the XML itself? For example:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" This is a test code, I want to make This word bold"/>

Here, is there any way in which I can make "This" bold, while leaving the rest as it is (In XML only and not in the Activity file)?


Solution

  • Try this:

    <string name="bold">abc<b>Enter_Text_Here_You_Want_To_BOLD</b>efg</string>
    

    And In XML:

    android:text="@string/bold"