Android Compose – Change Text font style to Italic

To change font style of Text composable to Italic, in Android Jetpack Compose, pass FontStyle.Italic for the optional fontStyle parameter of Text composable.

The following is a sample code snippet to set the font style to italic.

Text(
	"Hello World",
	fontStyle = FontStyle.Italic
)

Example

Create an Android Application with Jetpack Compose as template, and modify MainActivity.kt as shown in the following.

The Text composable in the following activity displays Hello World text in Italics.

MainActivity.kt

package com.example.myapplication

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontStyle
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    modifier = Modifier.fillMaxWidth()
                ) {
                    Text(
                        "Hello World",
                        fontStyle = FontStyle.Italic
                    )
                }
            }
        }
    }
}

Screenshot in Emulator

ADVERTISEMENT
Android Compose - Change Text font style to Italic

Conclusion

In this Android Jetpack Compose Tutorial, we learned how to change the font style of Text composable to Italic in Android Project with Jetpack Compose.