I am kind of new in Jetpack Compose and I am trying to customize the label on a TextField, I want the label to remain on the top of the TextField (like it is always focused) and not to be inside of the TextField.
I want it to be like it is on the top and not in the bottom.
Thanks!
Row(
modifier = Modifier
.fillMaxWidth()
) {
TextField(
value = text,
onValueChange = { newText ->
text = newText
},
label = {
Text(
text = "Nombre",
fontFamily = FontFamily(Font(R.font.quicksandregular)),
)
},
colors = TextFieldDefaults.colors(
cursorColor = azulApp,
unfocusedLabelColor = Color.LightGray,
focusedLabelColor = azulApp,
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent
),
textStyle = TextStyle(
fontFamily = FontFamily(Font(R.font.quicksandregular)),
fontSize = 15.sp,
),
singleLine = true,
modifier = Modifier
.fillMaxWidth()
)
}
I tried the code above with no result.
2
Answers
If you want to have a
TextField
always focused in Jetpack Compose, you have to use FocusRequester. So first of all you should declare a variable inside your composable function like this:Then inside your
TextField
you have to set thefocusRequester
:In the end, right after the
TextField
you have to request the focus as below:Another option is to use BasicTextField and add the label with the layout and position of your choice.