Android Jetpack Compose 无法更改 BasicTextField 光标拇指颜色。

4
目前我正在使用Android Jetpack Compose的BasicTextField。当我更改光标颜色时,我期望光标手柄也会以相同的颜色改变。但事实证明它显示为不同的颜色。这是一个bug还是我设置了错误的东西?
以下是我的设置:
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),
  )

enter image description here

1个回答

14
你需要提供一个自定义的TextSelectionColors。
类似这样:
val customTextSelectionColors = TextSelectionColors(
    handleColor = Green,
    backgroundColor = Red
)

CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
    BasicTextField(
        value = text,
        onValueChange = {text = it},
        cursorBrush = SolidColor(Black)
    )
}

enter image description here enter image description here


这在浅色模式下运行得很好,但是在深色模式下,柄和文本光标不可见,你有什么想法为什么会这样? - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接