Android Jetpack compose (1.0.0-beta07):TextField - None 可以使用提供的参数调用以下函数
Android Jetpack compose (1.0.0-beta07): TextField - None of the following functions can be called with the arguments supplied
我开始使用 Jetpack compose (1.0.0-beta07),然后我 运行 遇到了 TextField 的一个非常 st运行ge 问题。根据所有可能的文档和说明,我做的一切都是正确的,但是 Android Studio 不断给我写消息 None of the following functions can be called with the arguments supplied.
for 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)
)
}
您可以使用:
var text = remember { mutableStateOf("text") }
TextField(
value = text.value,
onValueChange = {
text.value = it
},
label = { Text(label) },
keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
)
或:
var text by remember { mutableStateOf("text") }
TextField(
value = text,
onValueChange = {
text = it
},
label = { Text(label) },
keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
)
您可以在官方文档中阅读有关 delegated properties 的更多信息。
我开始使用 Jetpack compose (1.0.0-beta07),然后我 运行 遇到了 TextField 的一个非常 st运行ge 问题。根据所有可能的文档和说明,我做的一切都是正确的,但是 Android Studio 不断给我写消息 None of the following functions can be called with the arguments supplied.
for 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)
)
}
您可以使用:
var text = remember { mutableStateOf("text") }
TextField(
value = text.value,
onValueChange = {
text.value = it
},
label = { Text(label) },
keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
)
或:
var text by remember { mutableStateOf("text") }
TextField(
value = text,
onValueChange = {
text = it
},
label = { Text(label) },
keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
)
您可以在官方文档中阅读有关 delegated properties 的更多信息。