[英]How to change the shape of a Row's border in Jetpack Compose?
How to change the shape of a Row
border in Jetpack Compose?如何在 Jetpack Compose 中更改
Row
边框的形状?
I'm creating a custom button in jetpack compose and for that I'm using a Row
to align the content horizontally.我在 jetpack compose 中创建了一个自定义按钮,为此我使用
Row
来水平对齐内容。 I need this custom button to have the following format:我需要这个自定义按钮具有以下格式:
However my code in compose renders the following element, without the rounded edges:但是,我在 compose 中的代码呈现以下元素,没有圆边:
The code for this compose function is below:这个 compose function 的代码如下:
@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)
}
I tried adding the clip
function call right after the border
call of the Modifier
like this:我尝试在
Modifier
器的border
调用之后添加clip
function 调用,如下所示:
@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)
}
But it didn't work either.但它也没有用。
I didn't understand exactly why but when I added a .padding
after the Modifier.border
statement the problem was solved:我不明白为什么,但是当我在
Modifier.border
语句后添加.padding
时,问题就解决了:
@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)
}
Result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.