16

我正在尝试创建一个圆形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)
    }

这是最终结果:

在此处输入图像描述

4

1 回答 1

34

您可以使用OutlinedButton.
就像是:

    OutlinedButton(onClick = { /*TODO*/ },
        modifier= Modifier.size(50.dp),  //avoid the oval shape
        shape = CircleShape,
        border= BorderStroke(1.dp, Color.Blue),
        contentPadding = PaddingValues(0.dp),  //avoid the little icon
        colors = ButtonDefaults.outlinedButtonColors(contentColor =  Color.Blue)
    ) {
         Icon(Icons.Default.Add, contentDescription = "content description")
    }

在此处输入图像描述

IconButton删除clip修饰符并使用参数shape内部border

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

在此处输入图像描述

于 2021-03-17T11:10:42.190 回答