KMP All Text Style Properties Guide Compose Multiplatform

Today’s tutorial will teach us about the Text widget in KMP Compose Multiplatform. We will discuss all text style properties in this guide on Compose Multiplatform.

KMP All Text Style Properties Guide Compose Multiplatform

KMP All Text Style Properties Guide Compose Multiplatform

Text is one of the most essential widgets on Compose Multiplatform. It allows developers to display text in the KMP application with all the text styling. In today’s tutorial, we will explore each Style property of the Text widget with a code example.

Properties of Text widget:

1. text: The text property is used to specify the Text content of the Text widget. We will pass Text in String format to this property.

2. modifier: The modifier property allows us to set padding, width, height, content alignment, and other UI properties of a widget. I have already explained all the properties in my other tutorial. You can read it from HERE.

3. style: The Style property of Text defines the typography of Text, such as Font size, weight, and color.

4. color: The Color property is used to set text color. It supports all formats for Color codes like Hex color code, RGBA color code, and Color constants.

  1. Set the Hex color code for Text in KMP.
  2. Set ARGB color code on Text.
  3. Set Color constants on Text.

5. fontSize: To set the font size in KMP. We have to use SP as a font-size property.

6. fontWeight: To set font thickness on the Text widget. The font-weight property has a few sub-properties.

Properties of font weight:

  1. FontWeight.Bold
  2. FontWeight.ExtraBold
  3. FontWeight.Thin
  4. FontWeight.W100
  5. FontWeight.Black
  6. FontWeight.ExtraLight
  7. FontWeight.Light
  8. FontWeight.Medium
  9. FontWeight.Normal
  10. FontWeight.SemiBold
  11. FontWeight.W200
  12. FontWeight.W300
  13. FontWeight.W400
  14. FontWeight.W500
  15. FontWeight.W600
  16. FontWeight.W700
  17. FontWeight.W800
  18. FontWeight.W900

7. fontStyle: Apply Italic or regular font style on the Text widget.

8. letterSpacing: To set the spacing between string characters in KMP.

9. textDecoration: To create Underline and Strike through text.

10. maxLines: To set the limit of lines displayed in Text.

11. overflow: To control text display when it overflows the current parent widget. This works when your text is large, and the root widget size is smaller.

12. textAlign: To set text alignment within its parent container widget.

Properties of text-align:

  1. TextAlign.Center
  2. TextAlign.End
  3. TextAlign.Left
  4. TextAlign.Right
  5. TextAlign.Start
  6. TextAlign.Justify
  7. TextAlign.Unspecified

Complete source code for App.kt file:

Screenshot:

KMP All Text Style Properties Guide

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *