Keyboard Options and Actions
Keyboard types, IME actions and focus.
Keyboard Options and Actions is a free Android Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Android Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Right Keyboard for the Job
A polished form shows the correct on-screen keyboard: digits for a phone, an @ key for email, a "Next" button to move between fields. Compose controls all of this with KeyboardOptions and KeyboardActions.
In this lesson you'll set keyboard types, IME actions, and manage focus between fields.
Choosing the Keyboard Type
Pass KeyboardOptions to a text field and set keyboardType. The system then shows a keyboard suited to the data.
Common values: Text, Number, Email, Phone, Password.
var email by remember { mutableStateOf("") }
OutlinedTextField(
value = email,
onValueChange = { email = it },
label = { Text("Email") },
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Email
)
)A Number Keyboard
For a quantity or PIN, use KeyboardType.Number. Combine it with input filtering so only digits are accepted, as you learned in the validation lesson.
var pin by remember { mutableStateOf("") }
OutlinedTextField(
value = pin,
onValueChange = { pin = it.filter { c -> c.isDigit() } },
label = { Text("PIN") },
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number
)
)Hiding a Password
Passwords should be masked. Use visualTransformation = PasswordVisualTransformation() together with the password keyboard type.
The state still holds the real characters; only the display is masked.
var password by remember { mutableStateOf("") }
OutlinedTextField(
value = password,
onValueChange = { password = it },
label = { Text("Password") },
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password
)
)The IME Action Button
The bottom-right key of the keyboard is the IME action. Set it with imeAction. Use Next to advance to the next field and Done on the final field.
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") },
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Next
)
)Responding to IME Actions
To react when the user taps that button, pass KeyboardActions. Each action (onNext, onDone, onSearch) is a lambda you implement.
Here pressing Done hides the keyboard.
val keyboard = LocalSoftwareKeyboardController.current
OutlinedTextField(
value = text,
onValueChange = { text = it },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = { keyboard?.hide() }
)
)Moving Focus to the Next Field
For a multi-field form, the Next button should jump to the following field. Use LocalFocusManager and call moveFocus.
val focusManager = LocalFocusManager.current
OutlinedTextField(
value = email,
onValueChange = { email = it },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(
onNext = { focusManager.moveFocus(FocusDirection.Down) }
)
)Clearing Focus on Done
On the last field, clearing focus dismisses the keyboard and deselects the field. Call focusManager.clearFocus() inside onDone.
OutlinedTextField(
value = password,
onValueChange = { password = it },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = { focusManager.clearFocus() }
)
)Requesting Focus Programmatically
Sometimes you want a field focused as soon as the screen appears, like a search box. Attach a FocusRequester and request focus in a LaunchedEffect.
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) { focusRequester.requestFocus() }
OutlinedTextField(
value = query,
onValueChange = { query = it },
modifier = Modifier.focusRequester(focusRequester),
label = { Text("Search") }
)Capitalization and Autocorrect
KeyboardOptions also controls capitalization and autoCorrectEnabled. Capitalize each word for a name, or turn off autocorrect for a username so it isn't mangled.
OutlinedTextField(
value = fullName,
onValueChange = { fullName = it },
label = { Text("Full name") },
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.Words,
autoCorrectEnabled = false
)
)Pure Kotlin: Choosing an IME Action
The logic of "Next for every field except the last, Done on the last" is plain Kotlin. Here we map field positions to the action label they should show.
fun imeActionFor(index: Int, lastIndex: Int): String =
if (index == lastIndex) "Done" else "Next"
fun main() {
val fields = listOf("name", "email", "password")
fields.forEachIndexed { i, field ->
println("$field -> ${imeActionFor(i, fields.lastIndex)}")
}
}Quick Check
You want the keyboard's bottom-right button to read "Next" and, when tapped, move focus to the field below. Which two pieces do you need?
Recap
You can now build keyboard-savvy forms:
KeyboardOptionssetskeyboardType,imeAction, capitalization and autocorrect.- Mask passwords with
PasswordVisualTransformation. KeyboardActionsresponds to Next/Done/Search.LocalFocusManagermoves or clears focus;FocusRequesterfocuses a field on demand.
That completes the form-building toolkit: input, state, validation and the keyboard. You're ready to build polished, friendly Compose forms.
Frequently asked questions
Is the “Keyboard Options and Actions” lesson free?
Yes — the full text of “Keyboard Options and Actions” is free to read here on the web, and the Android Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Android Academy course, upgrade to CoddyKit PRO.
What will I learn in “Keyboard Options and Actions”?
Keyboard types, IME actions and focus. You practise Android Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Android Academy?
No prior experience is required. Android Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Keyboard Options and Actions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Android Academy lesson?
Yes. Every Android Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- TextField and User Input
- Managing Form State
- Validating Input
- Keyboard Options and Actions