Android Jetpack Compose – Text Underline
To underline text in Text composable in Android Jetpack Compose, you can set the textDecoration parameter of the Text composable with TextDecoration.Underline (androidx.compose.ui.text.style.TextDecoration) value.
Example
In the following example, we underline the text of the Text composable using textDecoration parameter.
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.style.TextDecoration
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\nThis is some text\nAnd some more",
fontSize = 25.sp,
textDecoration = TextDecoration.Underline
)
}
}
}
}
}
Screenshot
Summary
In this tutorial, we have seen how to underline text in Text composable in Android Jetpack Compose, using textDecoration parameter of Text composable.