Jetpack Compose 中的左对齐按钮文本

问题描述 投票:0回答:1

我使用以下代码在 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
。然而,它总是居中对齐:

如何解决这个问题?

android android-jetpack-compose android-jetpack
1个回答
0
投票

在按钮内添加行

OutlinedButton(onClick = {  }, modifier = Modifier
        .fillMaxWidth()
        .height(48.dp)) {

        Row(modifier = Modifier.fillMaxWidth()) {
            Text(text = "Button Text", textAlign = TextAlign.Start)

        }


    }
© www.soinside.com 2019 - 2024. All rights reserved.