Jetpack Compose – Text Compose

Jetpack Compose, Google's advanced UI toolkit for Android, transforms the way user interfaces are built through a declarative Kotlin API. A key component of this toolkit is the Text composable, an essential element for presenting text. This article delves into the diverse capabilities of the Text composable, ranging from basic text rendering to more sophisticated styled and interactive text features.
RISE with SAP aims to unlock continued innovation and transformation for customers

Jetpack Compose, Google’s advanced UI toolkit for Android, transforms the way user interfaces are built through a declarative Kotlin API. A key component of this toolkit is the Text composable, an essential element for presenting text. This article delves into the diverse capabilities of the Text composable, ranging from basic text rendering to more sophisticated styled and interactive text features.

Basic Text Display

@Composable
fun BasicText() {
    Text(text = "Hello, World!")
}

This function displays a greeting message, which is straightforward and serves as a starting point for introducing text in UIs.

Styling Text

Jetpack Compose allows extensive customization of text appearance through various styling options:

@Composable
fun ColoredText() {
    Text(
        text = "Colored Text",
        color = Color.Blue,
        fontSize = 20.sp,
        fontFamily = FontFamily.Serif,
        fontStyle = FontStyle.Italic
    )
}

Important Attributes of Text

AttributesDescription
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. 
textDecorationthe decoration to be applied to the text
lineHeightthe height of each line of text.
overflowhow to handle overflowed text
softWrapwhether to wrap the text if it exceeds the width of its container.
maxLinesthe maximum number of lines for the text
minLinesthe minimum number of lines for the text.
onTextLayoutcallback that is invoked when the text is laid out.

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

Share:

More Posts

Navigation

Navigation helps you in understanding how your app moves across different components in your Application.

Android JetPack Navigation helps in implementing your high-level navigation in a go easy approach.