My Code
I tried to limit the length to a maximum of 30 characters, but if I write more than 30 characters, it will no longer be entered or erased. Why is that?
What I want to do is create a view that acts like EditText in xml.
The function you want.
- hint
- maxLength
However, the above two functions are not supported in Jetpack Compose TextField().
@Composable
fun MyCustomEditText(
placeholder: String = stringResource(id = "sample"),
) {
var inputText by remember { mutableStateOf("") }
BasicTextField(
value = inputText,
onValueChange = {if (it.length <= 30) inputText = it },
singleLine = false,
maxLines = 2,
decorationBox = { innerTextField ->
if (inputText.isEmpty()) { Text(text = placeholder)}
innerTextField()
}
)
}