You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Material3 CircularProgressIndicator无stroke参数,无法设置圆角帽求助

解决CircularProgressIndicator圆角样式问题

这种情况大多是因为你用的Compose版本太低——CircularProgressIndicator的stroke参数(支持配置StrokeCap)是在Compose Material 1.2.0及以上版本才新增的,低版本里这个组件确实没开放该参数,内部硬编码为Square。

给你几个可行的解决办法:

  • 升级Compose版本:在Module级的build.gradle里把Compose相关依赖版本升到1.2.0或更高,示例配置:

    implementation "androidx.compose.material:material:1.6.0"
    // 记得同步compose-ui、compose-compiler等其他相关依赖的版本
    

    升级后就能直接通过stroke参数设置圆角:

    CircularProgressIndicator(
        stroke = Stroke(width = 8.dp, cap = StrokeCap.Round)
    )
    
  • 自定义圆角进度条(暂时不能升级版本的话):用Canvas自己实现一个带圆角的圆形进度条,代码示例:

    @Composable
    fun RoundedCircularProgressIndicator(
        progress: Float,
        strokeWidth: Dp = 8.dp,
        color: Color = MaterialTheme.colors.primary,
        backgroundColor: Color = color.copy(alpha = 0.3f)
    ) {
        val strokeWidthPx = strokeWidth.toPx()
        Canvas(modifier = Modifier.size(48.dp)) {
            // 绘制背景圆环
            drawCircle(
                color = backgroundColor,
                style = Stroke(width = strokeWidthPx, cap = StrokeCap.Round)
            )
            // 绘制进度圆弧
            drawArc(
                color = color,
                startAngle = -90f,
                sweepAngle = progress * 360f,
                useCenter = false,
                style = Stroke(width = strokeWidthPx, cap = StrokeCap.Round)
            )
        }
    }
    

    使用时直接调用:

    RoundedCircularProgressIndicator(progress = 0.7f)
    

另外也可以检查下导包语句,确保你用的是androidx.compose.material.CircularProgressIndicator,别误导入了第三方UI库的同名组件。

内容的提问来源于stack exchange,提问作者Jozef Forgáč

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 13:42:42