如何制作TextField unclickable/unfocusable?
How to make TextField unclickable/unfocusable?
我有一个带有标签和文本的简单 OutlinedTextField
。
根据设计,它不应该集中 and/or 可键入。
在点击事件中,应用程序应该打开一个“选择器”对话框,并且在选择时,应该更新 TextField
的值。
因此,TextField 不应该:
- 可聚焦
- 打开键盘
- 接受文本插入或输入
它应该:
- 可点击
作为备用选项,我试着让一个简单的 Text
看起来像 OutlinedTextField
我认为让它看起来像 OutlinedTextField
更难。
有什么建议吗?
将enabled = false
添加到OutlinedTextField
When false
, the text field will be neither editable nor focusable, the input of the text field will not be selectable, visually text field will appear in the disabled UI state
OutlinedTextField(
value = text,
onValueChange = {
text = it
},
enabled = false
)
如果您想为禁用状态设置自定义颜色,只需添加:
colors = TextFieldDefaults.outlinedTextFieldColors(
disabledTextColor = LocalContentColor.current.copy(LocalContentAlpha.current),
disabledBorderColor = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled),
disabledLabelColor = MaterialTheme.colors.onSurface.copy(ContentAlpha.medium)
)
我有一个带有标签和文本的简单 OutlinedTextField
。
根据设计,它不应该集中 and/or 可键入。
在点击事件中,应用程序应该打开一个“选择器”对话框,并且在选择时,应该更新 TextField
的值。
因此,TextField 不应该:
- 可聚焦
- 打开键盘
- 接受文本插入或输入 它应该:
- 可点击
作为备用选项,我试着让一个简单的 Text
看起来像 OutlinedTextField
我认为让它看起来像 OutlinedTextField
更难。
有什么建议吗?
将enabled = false
添加到OutlinedTextField
When
false
, the text field will be neither editable nor focusable, the input of the text field will not be selectable, visually text field will appear in the disabled UI state
OutlinedTextField(
value = text,
onValueChange = {
text = it
},
enabled = false
)
如果您想为禁用状态设置自定义颜色,只需添加:
colors = TextFieldDefaults.outlinedTextFieldColors(
disabledTextColor = LocalContentColor.current.copy(LocalContentAlpha.current),
disabledBorderColor = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled),
disabledLabelColor = MaterialTheme.colors.onSurface.copy(ContentAlpha.medium)
)