我开始使用 Jetpack compose (1.0.0-beta07),但在 TextField 上遇到了一个非常奇怪的问题。根据所有可能的文档和说明,我做的一切都是正确的,但 Android Studio 不断给我写None of the following functions can be called with the arguments supplied.
消息TextField
下面是我编写的代码,其中 Studio 仍然在和 下划线Text (label)
,text = it
但我认为它在定义TextField
. 当我替换为 时问题消失remember {mutableStateOf ("text")}
,"text"
但TextField
在键入键盘时不会更改文本。
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.text.input.KeyboardType
@Composable
fun SimpleTextField(label: String = "Label", key: String = "unknown", keyboardType: KeyboardType = KeyboardType.Text){
var text = remember {
mutableStateOf("text")
}
TextField(
value = text,
onValueChange = {
text = it
},
label = { Text(label) },
keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
)
}