如何通过 Jetpack Compose 使用 Material TextField Composable 的 readOnly 属性

Jes*_*ill 5 android-jetpack-compose

我的用例是,我有一个表单,其中一些字段是手动填写的,其他字段将用户带到一个屏幕,他们可以在其中在一个大列表中搜索他们想要的值。仅接受用户输入的字段工作正常,但是当我尝试将属性添加readOnly = trueTextField可组合项时,出现以下错误:

\n
None of the following functions can be called with the arguments supplied.\nTextField(TextFieldValue, (TextFieldValue) \xe2\x86\x92 Unit, Modifier = ..., TextStyle = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., Boolean = ..., Int = ..., (ImeAction, SoftwareKeyboardController?) \xe2\x86\x92 Unit = ..., (SoftwareKeyboardController) \xe2\x86\x92 Unit = ..., InteractionState = ..., Color = ..., Color = ..., Color = ..., Color = ..., Shape = ...) defined in androidx.compose.material\nTextField(String, (String) \xe2\x86\x92 Unit, Modifier = ..., TextStyle = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., Boolean = ..., Int = ..., (ImeAction, SoftwareKeyboardController?) \xe2\x86\x92 Unit = ..., (SoftwareKeyboardController) \xe2\x86\x92 Unit = ..., InteractionState = ..., Color = ..., Color = ..., Color = ..., Color = ..., Shape = ...) defined in androidx.compose.material\n
Run Code Online (Sandbox Code Playgroud)\n

我假设此错误与我的参数与提供的覆盖不匹配有关TextField,但我似乎无法在文档中找到任何内容来了解​​如何使用此属性,而不是简单地为其提供一个Boolean值。我正在看这里寻找文档。

\n

代码是:

\n
None of the following functions can be called with the arguments supplied.\nTextField(TextFieldValue, (TextFieldValue) \xe2\x86\x92 Unit, Modifier = ..., TextStyle = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., Boolean = ..., Int = ..., (ImeAction, SoftwareKeyboardController?) \xe2\x86\x92 Unit = ..., (SoftwareKeyboardController) \xe2\x86\x92 Unit = ..., InteractionState = ..., Color = ..., Color = ..., Color = ..., Color = ..., Shape = ...) defined in androidx.compose.material\nTextField(String, (String) \xe2\x86\x92 Unit, Modifier = ..., TextStyle = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., (() \xe2\x86\x92 Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., Boolean = ..., Int = ..., (ImeAction, SoftwareKeyboardController?) \xe2\x86\x92 Unit = ..., (SoftwareKeyboardController) \xe2\x86\x92 Unit = ..., InteractionState = ..., Color = ..., Color = ..., Color = ..., Color = ..., Shape = ...) defined in androidx.compose.material\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用androidx.compose.material:material:1.0.0-alpha09Compose Material 包的版本alpha09我的其余 compose 依赖项。

\n

Jes*_*ill 5

readOnly在更新我的所有 compose 依赖项1.0.0-alpha10,然后使缓存无效并重新启动 Android Studio后,我能够使用该属性。

我发现这个属性被引入了,alpha10这就是我之前收到错误的原因。

以下是我用来得出这个结论的链接: