Change Text Size in TextView
To change the text size in TextView widget, set the textSize attribute with required dimensions.
TextView textSize in XML Layout
<TextView
android:textSize="20sp"
android:text="Hello World!" />
<TextView
android:textSize="30sp"
android:text="Hello World!" />
<TextView
android:textSize="40sp"
android:text="Hello World!" />
Example
Create an Android Application with Kotlin support and Empty Activity. Create three TextView widgets with different text sizes.
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:id="@+id/text_view_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="20sp"
android:text="Hello World!" />
<TextView
android:id="@+id/text_view_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="30sp"
android:text="Hello World!" />
<TextView
android:id="@+id/text_view_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textSize="40sp"
android:text="Hello World!" />
</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