Android 文本字段中是否有水平和垂直居中的文本?
在Android compose中,文本字段中是否有居中文本Android 文本字段中是否有水平和垂直居中的文本?,android,android-jetpack-compose,android-compose-textfield,Android,Android Jetpack Compose,Android Compose Textfield,在Android compose中,文本字段中是否有居中文本 TextField( value = text, onValueChange = setText, maxLines = 2, modifier = modifier .clip(RoundedCornerShape(10.dp)) .background(Color(0xffe2ebf0)) .border(BorderStroke(5.dp,
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() })
)
转到xml文件
并为EditText设置android:gravity=“center”
示例:
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="some text"
/>
您可以在
TextStyle
中使用textAlign=textAlign.Center
比如:
TextField(
//...your code
textStyle = MaterialTheme.typography.h3.copy(textAlign = TextAlign.Center),
)
问题是关于喷气式飞机组件的。与其他UI属性的Compose解决方案相比,这并不一定直观。当然,Compose从未听说过Demeter定律。。。