Android Jetpack Compose – Text Size

Android Jetpack Compose – Text Size

To set a specific size for the text in Text composable in Android Jetpack Compose, you can set the fontSize parameter of the Text composable with the required size.

Example

In the following example, we have set the font size of the Text composable to 30.sp.

MainActivity.kt

package com.example.myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.sp
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    Text(
                        text = "Hello Android!",
                        fontSize = 30.sp
                    )
                }
            }
        }
    }
}

Screenshot

Android Jetpack Compose - Text Size 30.sp
Text fontSize = 30.sp

Now, let us change the fontSize to 50.sp.

Text(
    text = "Hello Android!",
    fontSize = 50.sp
)

Screenshot

Android Jetpack Compose - Text Size 50.sp
Text fontSize = 50.sp

Summary

In this tutorial, we have seen how to set the font size of Text composable in Android Jetpack Compose, using fontSize parameter of Text composable.