@Composable
fun ColorMathInput() {
var text by remember { mutableStateOf("") }
TextField(
value = text,
onValueChange = { text = it },
textStyle = TextStyle(fontSize = 20.sp),
visualTransformation = { input ->
TransformedText(
buildAnnotatedString {
input.text.forEach { ch ->
when (ch) {
'+', '-', '*', '/' -> {
withStyle(
SpanStyle(color = Color.Red)
) {
append(ch)
}
}
else -> {
withStyle(
SpanStyle(color = Color.White)
) {
append(ch)
}
}
}
}
},
OffsetMapping.Identity
)
},
colors = TextFieldDefaults.textFieldColors(
containerColor = Color.Black,
cursorColor = Color.White
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
}