如果在jetpack compose中使用了vectorpainter,则线圈占位符不会显示

问题描述 投票:0回答:3

我正在使用以下代码来显示图像。

       AsyncImage(
               model = createImageUrl(audio.image_path),
                   contentDescription = "Song Artwork",
                    modifier = Modifier.fillMaxHeight()
                                       .aspectRatio(1f)
                                       .padding(horizontal = 4.dp),
                    placeholder = rememberVectorPainter(image = Icons.Outlined.MusicNote)
                )

未显示占位符图像。但是,如果我使用 placeHolder = PainterResource(R.drawable.someDrawableInMyResource),则加载图像时会显示可绘制对象。

我做错了什么?

image android-jetpack-compose placeholder image-loading coil
3个回答
5
投票
var loaded by remember {
        mutableStateOf(false)
    }
    AsyncImage(
        model = createImageUrl(audio.image_path),
        contentDescription = "Song Artwork",
        modifier = Modifier.fillMaxHeight().aspectRatio(1f).padding(horizontal = 4.dp),
        placeholder = rememberVectorPainter(image = Icons.Default.MusicNote),
        error = rememberVectorPainter(image = Icons.Default.MusicNote),
        fallback = rememberVectorPainter(image = Icons.Default.MusicNote),
        onSuccess = {
            loaded = true
        },
        colorFilter = if (!loaded) ColorFilter.tint(LocalContentColor.current) else null
    )

我使用了这个解决方法并且有效。我愿意接受其他干净的建议。


0
投票

我发现我做错了什么。我处于深色主题中,图像矢量的色调颜色与我的背景相匹配,因此没有显示任何内容。

可以帮助某人。

编辑:我的问题改变了..如何更改占位符色调以匹配我的主题?


0
投票

查看这个问题和解决方案:

© www.soinside.com 2019 - 2024. All rights reserved.