https://kotlinlang.org logo
#glance
Title
# glance
n

Nat Strangerweather

11/01/2023, 6:04 PM
If I wanted my widget background to be Material You colors, how would I go about it/ I currently have :
Copy code
Row( modifier = GlanceModifier.fillMaxSize()){}
But that gives me a transparent background. If I add a
background
modifier, I have to hardcode my color. My
Buttons
in the
Row
are Material You when I don't hardcode a color.
c

Chrimaeon

11/01/2023, 6:33 PM
how do you initialize the
MaterialTheme
? you can use
MaterialTheme.colorScheme.background
if you initialized the Theme with dynamic colors. https://developer.android.com/jetpack/compose/designsystems/material3
n

Nat Strangerweather

11/01/2023, 6:36 PM
Aaah I see! Thanks that's perfect!
Actually, what do you mean when you say "if you initialized the Theme with dynamic colors"? I am using the theme as it was set up out of the box in my project. My background is now white, whatever wallpaper I use. Is there something extra I need to set up? @Chrimaeon
c

Chrimaeon

11/01/2023, 9:43 PM
So follow the link I posted - you need to setup a dynamic color scheme.
👍 1
b

bbade_

11/03/2023, 6:26 PM
There are some glance demos that show how to do this. Everything in this directory is intended to serve as an example for how to use various glance concepts. Caveat: they're a bit less refined than the examples in our developer.android.com documentation. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:glance/g[…]on-tests/demos/src/main/java/androidx/glance/appwidget/demos/
Specifically, this demo has examples of material 3 dynamic, and then user provided m2 and m3 schemes https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:glance/g[…]ava/androidx/glance/appwidget/demos/DefaultColorsAppWidget.kt
n

Nat Strangerweather

11/04/2023, 9:33 AM
Many thanks for this @bbade_ , that's hugely helpful. I also found this: https://developer.android.com/jetpack/compose/glance/theme which solved the problem for me. Basically, I needed to use
GlanceTheme.colors.primaryContainer
and to wrap my widget in
GlanceTheme {}
.
🙂 1
2 Views