我使用以下代码在 Jetpack Compose 中创建
OutlinedButton
:
OutlinedButton(
colors = ButtonDefaults.outlinedButtonColors(Color.Transparent),
border = BorderStroke(0.dp, Color.Transparent),
modifier = Modifier.fillMaxWidth()
.background(
color = Color.Transparent,
shape = RectangleShape, // Oval shape
//border = androidx.compose.ui.drawBorder(2.dp, Color.Red) // Border color and width
),
onClick = {}
) {
Text(
modifier = Modifier.padding(horizontal = 0.dp, vertical = 0.dp),
color = Color.Black,
text = text,
textAlign = TextAlign.Left,
fontSize = 15.sp,
)
}
我尝试使用
TextAlign.Left
和TextAlign.Start
。然而,它总是居中对齐:
如何解决这个问题?
在按钮内添加行
OutlinedButton(onClick = { }, modifier = Modifier
.fillMaxWidth()
.height(48.dp)) {
Row(modifier = Modifier.fillMaxWidth()) {
Text(text = "Button Text", textAlign = TextAlign.Start)
}
}