Theming in Compose
In the previous section, we learned how to handle user actions and how to manage the state of a particular screen. But how do we keep our application’s user interface elements consistent across the entire application? In this section, we will look at how we can create reusable elements that are linked to the application’s theme.
You may have noticed, when you carried out the previous exercises, that Android Studio created some files in a ui.theme
package. This is because Jetpack Compose is built upon the Material Design library and will assign a theme to your application that is built on Material Design. The approach taken is the following:
- In the
Color.kt
file, all the colors of the application are declared:val Purple200 = Color(0xFFBB86FC) val Purple500 = Color(0xFF6200EE) val Purple700 = Color(0xFF3700B3) val Teal200 = Color(0xFF03DAC5)
In the preceding example, we have the color hexadecimal names.
- In
Shape.kt
, the following...