1

在 Android compose 中是否有在 TextField 中居中文本?

    TextField(
    value = text,
    onValueChange = setText,
    maxLines = 2,
    modifier = modifier
        .clip(RoundedCornerShape(10.dp))
        .background(Color(0xffe2ebf0))
        .border(BorderStroke(5.dp, color = MaterialTheme.colors.secondary), shape = RoundedCornerShape(1.dp)),
    textStyle = MaterialTheme.typography.h3,
    keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
    keyboardActions = KeyboardActions(onDone = { submit() })

)

还不能发布图片...所以这里有一个链接!

4

2 回答 2

1

您可以textAlign = TextAlign.CenterTextStyle.

就像是:

TextField(
    //...your code
    textStyle = MaterialTheme.typography.h3.copy(textAlign = TextAlign.Center),
)

在此处输入图像描述

于 2021-05-26T16:56:09.467 回答
-2

转到 xml 文件并为 EditText 设置 android:gravity="center"

示例:

<EditText
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"
    android:text="some text"
/>
于 2021-05-26T16:56:01.613 回答