Sitemap

Exploring Text Decorations in Compose

3 min readAug 12, 2025
Press enter or click to view image in full size
Photo by Jonathan Kemper on Unsplash

In UI development, text styling goes beyond just font sizes and colors. Adding visual cues like underlines or strikethroughs can significantly enhance readability and convey specific meanings. Jetpack Compose provides the TextDecoration parameter, which allows you to easily apply these visual enhancements to your text. A TextDecoration defines a horizontal line to be drawn on the text. In this blog post, we'll delve into how to use the TextDecoration parameter in your Jetpack Compose Text composables, exploring its different types and how to combine them for more complex styling.

Understanding Text Decoration

Let’s look at how TextDecoration is used with the Text composable.

Basic Text with No Decoration

To begin, a Text composable is used with no special decoration, serving as our baseline:

Text(
text = "Sample Text",
fontSize = 18.sp ,
textDecoration = TextDecoration.None
)

Here, TextDecoration.None explicitly states that no line is drawn on the text.

Applying Underline and Line-Through

The TextDecoration object provides predefined styles, such as Underline and LineThrough. You can apply these directly:

Text(
text = "Underlined Text",
textDecoration = TextDecoration.Underline
)

Text(
text = "Strikethrough Text",
textDecoration = TextDecoration.LineThrough
)

These examples show how to apply a single type of decoration, either an underline or a line through the text.

Combining Text Decorations

One powerful feature of TextDecoration is the ability to combine multiple decorations. This allows for more complex visual styles, such as having both an underline and a strikethrough.

You can combine them using the plus operator:

Text(
text = "You can combine them too",
textDecoration = TextDecoration
.LineThrough
.plus(
TextDecoration.Underline
)
)

Alternatively, you can use the TextDecoration.combine function, which takes a list of TextDecoration objects:

Text(
text = "or like this",
textDecoration = TextDecoration.combine(
listOf(
TextDecoration.LineThrough,
TextDecoration.Underline
)
)
)

Both methods achieve the same result: applying both LineThrough and Underline to the text simultaneously. This is particularly useful for indicating removed content that also needs emphasis, or similar scenarios.

Conclusion

The TextDecoration parameter in Jetpack Compose's Text composable offers a straightforward yet powerful way to enhance your text's appearance. Whether you need a simple underline, a strikethrough, or a combination of both, TextDecoration provides the flexibility to achieve the desired visual effect. By leveraging these features, you can create more informative and visually engaging user interfaces in your Android applications.

LinkedIn

Love you all.

Stay tune for upcoming blogs.

--

--

No responses yet