代码之家  ›  专栏  ›  技术社区  ›  Raj Narayanan

图标按钮内部可绘制的图标是黑色的,尽管它是白色的

  •  0
  • Raj Narayanan  · 技术社区  · 2 年前

    Icon 可在内部绘制 IconButton composable是黑色的,尽管它是白色的。下图显示了当前设置的右上角的垃圾桶图标 alpha

    enter image description here

    @Composable
    fun AppImage(
        modifier: Modifier = Modifier,
        imageUri: Uri = Uri.EMPTY,
        contentScale: ContentScale = ContentScale.None,
        contentDescription: String? = null,
        loadingImage: @Composable (SubcomposeAsyncImageScope.(AsyncImagePainter.State.Loading) -> Unit)? = null,
        successResult: @Composable (SubcomposeAsyncImageScope.(AsyncImagePainter.State.Success) -> Unit)? = null,
        errorResult: @Composable (SubcomposeAsyncImageScope.(AsyncImagePainter.State.Error) -> Unit)? = null
    ) {
        Card(
            modifier = Modifier
                .height(250.dp)
                .width(350.dp)
                .padding(15.dp)
                .clickable(
                    indication = null,
                    interactionSource = remember { MutableInteractionSource() }) {
                },
            elevation = 7.dp
        ) {
            Box(
                modifier = Modifier
                    .padding(16.dp)
                    .wrapContentSize(Alignment.Center)
            ) {
                SubcomposeAsyncImage(
                    model = imageUri,
                    modifier = modifier,
                    contentScale = contentScale,
                    contentDescription = contentDescription,
                    loading = loadingImage,
                    success = successResult,
                    error = errorResult
                )
    
                IconButton(
                    onClick = {},
                    modifier = Modifier
                        .clip(CircleShape)
                        .background(color = Color.Black.copy(alpha = 0.5f))
                        .align(Alignment.TopEnd)
                        .size(33.dp)
                ) {
                    Icon(
                        painterResource(id = R.drawable.ic_filled_delete_30),
                        contentDescription = "Delete Item Picture",
                        modifier = Modifier
                            .clickable(onClick = {
                            })
                    )
                }
            }
        }
    }
    
    1 回复  |  直到 2 年前
        1
  •  2
  •   Thracian    2 年前

    您可以使用图标的着色属性更改可绘制的颜色

    @Composable
    fun Icon(
        painter: Painter,
        contentDescription: String?,
        modifier: Modifier = Modifier,
        tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
    )