英文:
Android Jetpack Compose cannot change BasicTextField cursor thumb color
问题
目前我正在使用Android Jetpack Compose的BasicTextField。当我更改光标颜色时,我希望光标手柄的颜色也会相应更改为相同的颜色。但实际情况是光标手柄显示为不同的颜色。这是一个错误吗,还是我设置错了什么?
这是我所设置的内容:
colors = TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent,
focusedIndicatorColor = colorResource(id = R.color.accent),
unfocusedIndicatorColor = colorResource(id = R.color.lightest_grey),
focusedLabelColor = colorResource(id = R.color.secondary_20),
unfocusedLabelColor = colorResource(id = R.color.light_grey),
textColor = colorResource(id = R.color.secondary),
cursorColor = colorResource(id = R.color.secondary),
)
英文:
Currently I'm working with android jetpack compose BasicTextField. And when I change cursor color, I expect the cursor handle to be changed with the same color as well. But it turns out with a different color. Is this a bug or I did set something wrong?
Here is what I have set
colors = TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent,
focusedIndicatorColor = colorResource(id = R.color.accent),
unfocusedIndicatorColor = colorResource(id = R.color.lightest_grey),
focusedLabelColor = colorResource(id = R.color.secondary_20),
unfocusedLabelColor = colorResource(id = R.color.light_grey),
textColor = colorResource(id = R.color.secondary),
cursorColor = colorResource(id = R.color.secondary),
)
答案1
得分: 11
你需要提供一个自定义的**TextSelectionColors
**。
类似这样:
val customTextSelectionColors = TextSelectionColors(
handleColor = Green,
backgroundColor = Red
)
CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
BasicTextField(
value = text,
onValueChange = {text = it},
cursorBrush = SolidColor(Black)
)
}
英文:
You have to provide a custom TextSelectionColors
.
Something like:
val customTextSelectionColors = TextSelectionColors(
handleColor = Green,
backgroundColor = Red
)
CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
BasicTextField(
value = text,
onValueChange = {text = it},
cursorBrush = SolidColor(Black)
)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论