Android TextView – Text Style

TextView Text Style

You can change the text style in TextView widget to bold, italic, normal or bold|italic using the textStyle attribute of the widget.

The default value of textStyle attribute for TextView is normal.

<TextView
    android:textStyle="normal"
    android:text="Normal Text" />

<TextView
    android:textStyle="italic"
    android:text="Italic Text" />
	
<TextView
    android:textStyle="bold"
    android:text="Bold Text" />

<TextView
    android:textStyle="bold|italic"
    android:text="Bold Italic Text" />
Android TextView - Text Style

Example

Create an Android Application with Kotlin support and Empty Activity. Create four TextView widgets with different text styles: normal, italic, bold and bold|italic respectively.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textSize="30sp"
        android:textAlignment="center"
        android:textStyle="normal"
        android:text="Normal Text" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textSize="30sp"
        android:textAlignment="center"
        android:textStyle="italic"
        android:text="Italic Text" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textSize="30sp"
        android:textAlignment="center"
        android:textStyle="bold"
        android:text="Bold Text" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textSize="30sp"
        android:textAlignment="center"
        android:textStyle="bold|italic"
        android:text="Bold Italic Text" />

</LinearLayout>

MainActivity.kt

package com.kotlinandroid.myapp

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

Screenshot

Android TextView - Text Style - Example