You need to enable JavaScript to run this app. 如何使用Jetpack Compose实现中心带图标的圆形OutlinedButton
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Jetpack Compose实现中心带图标的圆形OutlinedButton

Compose 圆形图标按钮实现问题

尝试在界面中实现中心放置图标、无文字的圆形轮廓按钮,最初基于OutlinedButton编写了如下代码:

OutlinedButton(
    onClick = { /*TODO*/ },
    shape = CircleShape,
    border = BorderStroke(1.dp, Color.Blue)
) {
    Icon(Icons.Default.Add, contentDescription = "content description")
}

实际运行后生成的按钮呈椭圆形,效果如下:
椭圆形按钮效果

后续调整实现方案,改用IconButton编写代码:

IconButton(
    onClick = { },
    modifier = Modifier
        .clip(CircleShape)
        .border(1.dp, Color.Red)
) {
    Icon(
        Icons.Default.Add, 
        contentDescription = "content description",
        tint = Color.Red
    )
}

这版代码的运行效果如下:
IconButton实现效果


内容的提问来源于stack exchange,提问作者Gabriele Mariotti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.30 06:36:04