Typography in KMP MaterialTheme Reusable Text Styles Guide

In today’s tutorial, we will learn about Typography in MaterialTheme in the Kotlin Compose Multiplatform KMP Android and iOS application. We will discuss typography usage, implementation, and benefits.

Typography in KMP MaterialTheme Reusable Text Styles Guide

Typography in KMP MaterialTheme Reusable Text Styles Guide

We can define custom reusable text styles using typography in the Root widget of MaterialTheme, which can then be used unlimited times in our application. This will remove code redundancy in our app. We can define all types of Text styles before starting app design from Figma. This will eventually lead to a faster development cycle.

Already exist ready-to-use typography in MaterialTheme:

1. h1: heading 1

2. h2: heading 2

3. h3: heading 3

4. h4: heading 4

5. h5: heading 5

6. h6: heading 6

7. subtitle 1: As large-size paragraph text.

8. subtitle 2: Small subtitle paragraph text.

9. body 1: Normally used body text size.

10. body 2: Small body text size.

11. button: Standard button text style.

12. caption: For caption text style.

13. overline: Samll text with line height set.

As of now, there are 13 inbuilt custom style sheets available in KMP for text widgets.

How to define custom typography in KMP compose multiplatform?

You cannot create a new Typography property in KMP but override the existing one. In KMP Compose Multiplatform they have already defined all the text styles that we might use in an application. We can override any typography as per our usage.

Complete source code for App.kt file:

Screenshot in Android:

Typography in Android in KMP

Screenshot in iOS device:

Typography in iOS in KMP

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 *