Hi! Is it possible to do the following in Glance c...
# glance
k
Hi! Is it possible to do the following in Glance composables? • add elevation (e.g. in a Row)? Like you can in a LinearLayout? • tint a drawable
p
1. IDK 2. Unfortunately not, but as a work around I make bitmap and color it accordingly
k
Thank you for your answer 🙂 When you say bitmap, you mean something like this and having the color applied to the drawable itself?
Copy code
modifier = GlanceModifier.background(imageProvider = ImageProvider(R.drawable.colored_drawable)),
p
I actually create the bitmap with different color every time the color changes.
Copy code
fun createColorArc(context: Context, colorString: String): Bitmap {
        val density = context.resources.displayMetrics.density
        val bitmap = Bitmap.createBitmap(
            36f.times(density).toInt(),
            36f.times(density).toInt(),
            Bitmap.Config.ARGB_8888
        )
        val paintWidth = 3f.times(density)
        val paint = Paint().apply {
            isAntiAlias = true
            color = Color.parseColor(colorString)
            strokeWidth = paintWidth
            style = Paint.Style.STROKE
            strokeCap = Paint.Cap.ROUND
        }
        val canvas = Canvas(bitmap)
        canvas.drawArc(
            paintWidth,
            paintWidth,
            canvas.width.toFloat().minus(paintWidth),
            canvas.height.toFloat().minus(paintWidth),
            45f,
            250f,
            false,
            paint
        )
        return bitmap
    }
🙌 1
calling this from glance composable:
Copy code
Image(
                modifier = GlanceModifier.size(36.dp),
                provider = ImageProvider(
                    bitmap = WidgetUiHelper.createColorArc(
                        context,
                        data.colorHex
                    )
                ),
                contentDescription = "Color arc"
            )
p
For your first question, sadly,
setElevation
has only been made available to
RemoteViews
on Android 12. Prior to this, app widgets can only set their elevation in XML.
👍 1
Allowing changing the elevation would therefore only work on Android 12+ for Glance.
k
I see.. Thank you for the clarification 🙂 So, is the same true with
setBackgroundTintList
for tinting background drawables?