Я хочу сделать то же самое, но для текстового поля.
Как изменить цвет контура OutlinedTextField из Jetpack Compose?
Послушайте код моего текстового поля:
Код: Выделить всё
TextField(
value = currentWeight,
modifier = Modifier
.fillMaxWidth()
.padding(5.dp),
onValueChange = { currentWeight = it },
label = { Text(text = "Mevcut kilon (kg)") },
shape = RoundedCornerShape(5.dp),
colors = TextFieldDefaults.textFieldColors(
textColor = Grey2,
disabledTextColor = Color.Transparent,
backgroundColor = Grey3,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
)
)
[img]https://i. sstatic.net/ddQK5.png[/img]
Я добавил цвет метки фокуса в часть цветов текстового поля, но это не сработало
РЕДАКТИРОВАТЬ
Я сделал это так @Gabriele Mariotti, но есть некоторые проблемы
Код: Выделить всё
val interactionSource = remember { MutableInteractionSource() }
val isFocused = interactionSource.collectIsFocusedAsState()
val shape = RoundedCornerShape(2.dp)
val borderModifier = if (isFocused.value) Modifier.border(1.dp,Red, shape) else Modifier
val singleLine = true
val enabled = true
BasicTextField(
value = currentWeight,
onValueChange = { currentWeight = it },
interactionSource = interactionSource,
enabled = enabled,
singleLine = singleLine,
modifier = borderModifier.background(
color = TextFieldDefaults.textFieldColors().backgroundColor(true).value,
shape = shape
)
) {
TextFieldDefaults.TextFieldDecorationBox(
value = currentWeight,
innerTextField = it,
singleLine = singleLine,
enabled = enabled,
label = { Text("Label") },
placeholder = { Text("Placeholder") },
visualTransformation = VisualTransformation.None,
interactionSource = interactionSource,
colors = TextFieldDefaults.textFieldColors()
)
}
Код: Выделить всё
TextFieldDefaults.TextFieldDecorationBox
And `Text()`
Код: Выделить всё
label = { Text("Label") },
placeholder = { Text("Placeholder") },
Код: Выделить всё
@Composable invocations can only happen from the context of a @Composable function

Подробнее здесь: https://stackoverflow.com/questions/752 ... ck-compose