Android Jetpack Compose – Text Italic

Android Jetpack Compose – Text Italic

To set italic text in Text composable in Android Jetpack Compose, you can set the fontStyle parameter of the Text composable with FontStyle.Italic (androidx.compose.ui.text.font.FontStyle) value.

Example

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

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.FontStyle
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,
                        fontStyle = FontStyle.Italic
                    )
                }
            }
        }
    }
}

Screenshot

Android Jetpack Compose - Text Italic
Text fontStyle = FontStyle.Italic

Summary

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