How to set the inputType for a TextField in Jetpack Compose
I'd like to restrict what the user can type in a TextField in Jetpack Compose. How do I do that?
The equivalent in xml is inputType
:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="Only numbers please!" />
Use KeyboardOptions:
TextField(
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
You can use something like:
TextField(
....,
keyboardOptions =
KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number)
)