Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 文本字段中是否有水平和垂直居中的文本?_Android_Android Jetpack Compose_Android Compose Textfield - Fatal编程技术网

Android 文本字段中是否有水平和垂直居中的文本?

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,

在Android compose中,文本字段中是否有居中文本

    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定律。。。