VOOZH about

URL: https://www.geeksforgeeks.org/android/text-in-android-using-jetpack-compose/

⇱ Text in Android using Jetpack Compose - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Text in Android using Jetpack Compose

Last Updated : 23 Jul, 2025

Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. Android Text is a simple view in Android which is used to display text inside our App.

In this article, we will take a look at the implementation of Text in Android using Jetpack Compose. 

Important Attributes of Text

Attributes

Description

textto set the text which we have to display inside our Text.
style to change the style of Text in Android.
colorto change the color of Text.
fontSizeto change the font size of our text. 
fontWeight to set the weight for our font ie. to extra bold, dark, and many more
fontStyleto set font style to italic.
fontFamilyto change the font family of our text.
letterSpacingto set spacing in between letters of our Text.  
backgroundto set the background color for our Text. 
shadowto add a shadow for our Text.  
textAlignto change the alignment of our Text.
modifierthe modifier is used to add padding to our Text. 

textDecoration

the decoration to be applied to the text

lineHeight

the height of each line of text.

overflow

how to handle overflowed text

softWrap

whether to wrap the text if it exceeds the width of its container.

maxLines

the maximum number of lines for the text

minLines

the minimum number of lines for the text.

onTextLayout

callback that is invoked when the text is laid out.

Step by Step Implementation

Step 1: Create a New Project

To create a new project in the Android Studio Canary Version please refer to How to Create a new Project in Android Studio Canary Version with Jetpack Compose.

Step 2: Adding Text in MainActivity.kt file

Navigate to the app > java > your app's package name and open the MainActivity.kt file. Inside that file add the below code to it.

👁 text-compose-dir


Comments are added inside the code to understand the code in more detail.

MainActivity.kt:

Output:

👁 text-compose


Modifying Text further in Jetpack Compose

In this example we are adding some extra functionality to the Text.

MainActivity.kt:

Output: 

👁 text-compose-2


Comment

Explore