Skip to content

Material Theming: Android Basics with Compose - Theme colors not applying to Card Composable #132

@ParaMigi

Description

@ParaMigi

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-material-theming?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-3-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-material-theming#3

In which task and step of the codelab can this issue be found?
4: Add color

Describe the problem
The Card Composable does not use the correct color. It uses surfaceContainerHigh, which you forgot to define, so it defaults to some kind of purple. In fact, there are some additional colors you forgot to define. In the Theme.kt file:

    surfaceBright = md_theme_light_surfaceBright,
    surfaceContainer = md_theme_light_surfaceContainer,
    surfaceContainerHigh = md_theme_light_surfaceContainerHigh,
    surfaceContainerHighest = md_theme_light_surfaceContainerHighest,
    surfaceContainerLow = md_theme_light_surfaceContainerLow,
    surfaceContainerLowest = md_theme_light_surfaceContainerLowest,
    surfaceDim = md_theme_light_surfaceDim
    
    surfaceBright = md_theme_dark_surfaceBright,
    surfaceContainer = md_theme_dark_surfaceContainer,
    surfaceContainerHigh = md_theme_dark_surfaceContainerHigh,
    surfaceContainerHighest = md_theme_dark_surfaceContainerHighest,
    surfaceContainerLow = md_theme_dark_surfaceContainerLow,
    surfaceContainerLowest = md_theme_dark_surfaceContainerLowest,
    surfaceDim = md_theme_dark_surfaceDim

and in the Color.kt file:

val md_theme_light_surfaceBright = Color(0xfff5fbf5)
val md_theme_light_surfaceContainer = Color(0xffeaefea)
val md_theme_light_surfaceContainerHigh = Color(0xFFe4eae4)
val md_theme_light_surfaceContainerHighest = Color(0xFFdee4de)
val md_theme_light_surfaceContainerLow = Color(0xFFeff5ef)
val md_theme_light_surfaceContainerLowest = Color(0xFFffffff)
val md_theme_light_surfaceDim = Color(0xFFd6dbd6)

val md_theme_dark_surfaceBright = Color(0xFF353b37)
val md_theme_dark_surfaceContainer = Color(0xFF1b211e)
val md_theme_dark_surfaceContainerHigh = Color(0xFF252b28)
val md_theme_dark_surfaceContainerHighest = Color(0xFF303632)
val md_theme_dark_surfaceContainerLow = Color(0xFF171d1a)
val md_theme_dark_surfaceContainerLowest = Color(0xFF0a0f0c)
val md_theme_dark_surfaceDim = Color(0xFF0f1512)

(I'm not going to make all the letters in the hex code capitals, you can do that yourself, these were taken directly from the Material Theme Builder)

Steps to reproduce?
N.A.

Versions
Android Studio version: android-studio-2024.3.1.14-windows
API version of the emulator: N.A.

Additional information
Include screenshots if they would be useful in clarifying the problem.
N.A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions