问题描述
如何在Jetpack组合中更改Row边框的形状?
我正在jetpack中创建一个自定义按钮,为此,我使用一个Row水平对齐内容。我需要这个自定义按钮具有以下格式:

但是,我在compose中的代码呈现以下元素,没有圆角:

此组合函数的代码如下:
@Composable
fun LargeQuantityButton(
modifier: Modifier = Modifier,
onPlusClick: () -> Unit,
onMinusClick: () -> Unit,
text: String,
) = Row(
modifier = modifier
.border(
border = ButtonDefaults.outlinedBorder,
shape = RoundedCornerShape(4.dp)
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
RemoveIcon(action = onMinusClick)
Text(
text = text,
fontWeight = FontWeight.W400
)
AddIcon(action = onPlusClick)
}我的尝试失败了
我尝试在clip的border调用之后添加Modifier函数调用,如下所示:
@Composable
fun LargeQuantityButton(
modifier: Modifier = Modifier,
onPlusClick: () -> Unit,
onMinusClick: () -> Unit,
text: String,
) = Row(
modifier = modifier
.border(border = ButtonDefaults.outlinedBorder)
.clip(shape = RoundedCornerShape(4.dp)),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
RemoveIcon(action = onMinusClick)
Text(
text = text,
fontWeight = FontWeight.W400
)
AddIcon(action = onPlusClick)
}但也没用。
发布于 2022-02-23 02:32:14
我不明白为什么,但是当我在.padding语句之后添加一个Modifier.border语句时,问题就解决了:
@Composable
fun LargeQuantityButton(
modifier: Modifier = Modifier,
onPlusClick: () -> Unit,
onMinusClick: () -> Unit,
text: String,
) = Row(
modifier = modifier
.border(
border = ButtonDefaults.outlinedBorder,
shape = RoundedCornerShape(4.dp)
)
.padding(PaddingValues(horizontal = 8.dp)),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
RemoveIcon(action = onMinusClick)
Text(
text = text,
fontWeight = FontWeight.W500
)
AddIcon(action = onPlusClick)
}结果:

https://stackoverflow.com/questions/71230508
复制相似问题