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

TRo*_*ose 9 android textfield android-jetpack-compose android-compose-textfield

目前我正在使用 android jetpack 撰写 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),
  )
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Gab*_*tti 22

您必须提供自定义TextSelectionColors.

就像是:

val customTextSelectionColors = TextSelectionColors(
    handleColor = Green,
    backgroundColor = Red
)

CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
    BasicTextField(
        value = text,
        onValueChange = {text = it},
        cursorBrush = SolidColor(Black)
    )
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述