Android Jetpack Compose – Text Bold

Android Jetpack Compose – Text Bold

To set a bold text in Text composable in Android Jetpack Compose, you can set the fontWeight parameter of the Text composable with FontWeight.Bold (androidx.compose.ui.text.font.FontWeight) value.

Example

In the following example, we have set the text of the Text composable to Bold.

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.text.font.FontWeight
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,
                        fontWeight = FontWeight.Bold
                    )
                }
            }
        }
    }
}

Screenshot

Android Jetpack Compose - Text Bold
Text fontWeight = FontWeight.Bold

Summary

In this tutorial, we have seen how to set bold text for Text composable in Android Jetpack Compose, using fontWeight parameter of Text composable.