How to Make Android TextView Text Bold


Make Android TextView Text Bold

In order to make the text of TextView bold, we can make use of the XML attribute textStyle with a value as bold,


Example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="My Text"
        android:textAlignment="center"
        android:textStyle="bold"
        android:id="@+id/myTextView"/>
</LinearLayout>


You may also achieve this programmatically by using the method setTypeface,

TextView textView = findViewById(R.id.myTextView);
Typeface bold = Typeface.defaultFromStyle(Typeface.BOLD);
textView.setTypeface(bold);

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap