google-developer-training / basic-android-kotlin-compose-training-woof

Apache License 2.0
54 stars 81 forks source link

Material Theming: Android Basics with Compose #43

Open tomasfrank412 opened 1 year ago

tomasfrank412 commented 1 year ago

Hi Hi 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?

step 2 of "Add color palette to theme" chapter

Describe the problem Hi, I have imported into my project code from step 2 of "Add color palette to theme" chapter, to the file Theme.kt. And the result is that I am getting error related to this part of code, specifically to shapes and typography lines.

MaterialTheme( colorScheme = colorScheme, shapes = Shapes, typography = Typography, content = content )

The error message is: Type mismatch: inferred type is androidx.compose.material.Shapes but androidx.compose.material3.Shapes was expected

As you can see in an attached file. I am a rookie and got stuck here. Hope it is not a false alarm. But i have checked also the solution code and did not find a hint, many thanks. Tomas

Kotlin_bug.docx

Steps to reproduce?

  1. See description aove

Versions Android Studio Flamingo | 2022.2.1 Patch 2 Build #AI-222.4459.24.2221.10121639, built on May 12, 2023 Runtime version: 17.0.6+0-b2043.56-9586694 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1280M Cores: 4 Registry: external.system.auto.import.disabled=true ide.text.editor.with.preview.show.floating.toolbar=false gradle.version.catalogs.dynamic.support=true

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

roodly-1804 commented 1 year ago

That s my code, instead of colors, use colorScheme.. i think there is some update in the synthaxe after the courses were made.. so sometimes you will need to modify thing a little. And there is another change, you will have to explicitly give the card colors because when i tried it, the surface color wasn t working for it. `private val DarkColorPalette = darkColorScheme( background = Cyan900, surface = Cyan700, onSurface = White, primary = Grey900, onPrimary = White, secondary = Grey100 )

private val LightColorPalette = lightColorScheme( background = Green100, surface = Green50, onSurface = Grey900, primary = Grey50, onPrimary = Grey900, secondary = Grey700 )

@Composable fun WoofTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = false, content: @Composable () -> Unit ) { val colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) }

    darkTheme -> DarkColorPalette
    else -> LightColorPalette
}
val view = LocalView.current
if (!view.isInEditMode) {
    SideEffect {
        val window = (view.context as Activity).window
        window.statusBarColor = colorScheme.primary.toArgb()
        WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
    }
}

MaterialTheme(
    colorScheme = colorScheme,
    typography = Typography,
    shapes = Shapes,
    content = content
)

}`