Glance Button with background causing Exception

74 views Asked by At

I've trying to create a Image Button with Glance on Android. The following Code throws an Exception

@Composable
@GlanceComposable
internal fun ReloadButton(
    modifier: GlanceModifier = GlanceModifier,
    onClick: () -> Unit,
) {
    Button(
        text = "",
        onClick = { onClick() },
        modifier =
            modifier.background(
                imageProvider = ImageProvider(R.drawable.ic_refresh),
            ).size(Grid.FOUR),
    )
}

The Error:

java.lang.IllegalStateException: There is no use case yet to support this colorFilter in S+ versions.
at androidx.glance.appwidget.translators.ImageTranslatorKt.applyColorFilter(ImageTranslator.kt:145)
at androidx.glance.appwidget.translators.ImageTranslatorKt.translateEmittableImage(ImageTranslator.kt:72)

For some reason the applyColorFilter method checks if is API Level S+ for whatever reason.

Why is a Button with an Background image not supported ? I've researched a bit the Problem, but i could not find any good answer why that happens.

Alternatively i can use a Image as "reload" button, but it feels wrong on the Widget. Anyone has a workaround ?

thanks and happy new year

1

There are 1 answers

0
Summers Pittman On

I've checked with the Glance team. The button only supports the color property on the button, and the background modifier isn't supported. As a workaround you can use a clickable image.