\n","author":{"@type":"Person","name":"TRose"},"upvoteCount":14,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"
You have to provide a custom TextSelectionColors
.
Something like:
\nval customTextSelectionColors = TextSelectionColors(\n handleColor = Green,\n backgroundColor = Red\n)\n\nCompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {\n BasicTextField(\n value = text,\n onValueChange = {text = it},\n cursorBrush = SolidColor(Black)\n )\n}\n
\n\n","author":{"@type":"Person","name":"Gabriele Mariotti"},"upvoteCount":40}}}Reputation: 472
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),
)
Upvotes: 14
Views: 8404
Reputation: 1
CompositionLocalProvider(
LocalTextSelectionColors provides TextSelectionColors(
handleColor = /*your custom color*/,
backgroundColor = /*your custom color*/
)
) {
//your composable
}
Upvotes: 0
Reputation: 364624
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)
)
}
Upvotes: 40