0

我写了一个 outlineTextField 并且 onValueChange 中的“它”在标签文本中不起作用

它不读取并且 Text 也显示错误。

val usernameState = rememberSaveable{ mutableStateOf(TextFieldValue) }

OutlinedTextField(
            value = usernameState.value,
            onValueChange = { usernameState.value = it },
            label = { Text(text = "username")}
        )

这是调用概述文本字段并进行设置的错误:

Modifier = ...,启用:Boolean = ...,只读:Boolean = ...,textStyle:TextStyle = ...,标签:(()-> Unit)?= ...,占位符:(()->单位)?= ...,leadingIcon:(()->单位)?= ..., trailingIcon: (() -> Unit)? = ..., isError: Boolean = ..., visualTransformation: VisualTransformation = ..., keyboardOptions: KeyboardOptions = ..., keyboardActions: KeyboardActions = ..., singleLine: Boolean = ..., maxLines: Int = . ..,interactionSource:MutableInteractionSource = ...,形状:Shape = ...,颜色:TextFieldColors = ...):在androidx.compose.material中定义的单位

4

1 回答 1

0

您需要提供 aString作为您正在使用的签名的值。因此,您传递的 value 参数应该是unserNameState.value.value. 第一个值是从 中提取状态值MutableState,第二个是String从中提取状态值TextFieldValue。此外,您需要TextFieldValue通过添加括号来初始化那里的构造函数。

我的建议是你选择最简单的方法。

var uns by remeberSaveable{ mutableStateOf("") } // Use 'by' to treat this state as a regular variable

OutlinedTextField(
 value = uns, // As simple as that
 onValueChange = { uns = it },
 label = { Text("User Name") }
)

考虑参加Codelabs,以更好地全面了解 Compose。

到目前为止,你在月球上雕刻了什么?

于 2022-02-05T18:08:19.563 回答