简体   繁体   English

OutlineTextField 、TextField 在 Jetpack Compose 1.0.0-alpha02 中不起作用

[英]OutlineTextField , TextField not working in Jetpack Compose 1.0.0-alpha02

For some reason, CoreTextField works but TextField and OutlineTextField wont出于某种原因,CoreTextField 有效但 TextField 和 OutlineTextField 不会

Works作品

@Composable
fun TextFieldDemo(){
    val text = remember { mutableStateOf(TextFieldValue("Text")) }
    CoreTextField(modifier = Modifier.fillMaxWidth(),
            value = text.value,
            onValueChange = {text.value = it})
}

Not working不工作

    @Composable
fun TextFieldDemo(){
    val text = remember { mutableStateOf(TextFieldValue("Text")) }
    OutlinedTextField(value = text.value,
            onValueChange = {text.value = it}, label = {Text("Test")})
}

Error: Non of the following Functions can be called for OutlinedTextField错误:不能为OutlinedTextField调用以下函数

From the docs change从文档更改

Bug Fixes

androidx.ui.foundation.TextFieldValue and androidx.ui.input.EditorValue are deprecated. TextField, FilledTextField and CoreTextField composables that uses that type is also deprecated. Please use androidx.ui.input.TextFieldValue instead (I4066d, b/155211005)

But I'm using what it says (I think)但我正在使用它所说的(我认为)

Edit编辑

在此处输入图片说明

You are missing the "label" param in the original question, as we can see in the image.正如我们在图像中看到的那样,您在原始问题中缺少“标签”参数。 Following Gabriele's comment made it work, so you shouldn't change the question with the answer, it's a lot confusing.遵循 Gabriele 的评论使它起作用,所以你不应该用答案来改变问题,这很令人困惑。

Just for the record, here it`s the code that works in 1.0.0-alpha02:只是为了记录,这是在 1.0.0-alpha02 中工作的代码:

@Composable
fun TextFieldDemo() {
    val text = remember { mutableStateOf(TextFieldValue("Text")) }
    OutlinedTextField(value = text.value,
        onValueChange = { text.value = it },
        label = { Text("Test") })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM