Member-only story
Android Keyboard Handling Using Jetpack Compose
Handle keyboard events effectively in your Android apps
In this article, we are going to learn how to manage the Android keyboard in jetpack compose. We’ll be focusing more on IME actions, keyboard types, focus listeners, etc.
Introduction
Jetpack Compose is one of the recent attempts by Google to make it easy for Android developers to build UI.
“Jetpack Compose is a modern toolkit for building native Android UI. Jetpack Compose simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs.” — Android Developers
Jetpack Compose is stable version 1.0 is released recently, which means it’s production-ready. So it would be a great time to learn how to work with the next-generation UI kit for Android development.
You will need to install Android Studio — Arctic Fox (2020.3.1) version to use the Jetpack Compose.
Prerequisites
Before going any further, you must have basic knowledge of how to work with Jetpack Compose. If you’re new to Compose, I highly recommend going through the following articles:
- “Jetpack Compose Components (Part 1)”
- “Explore Android Bottom Sheets in Jetpack Compose”
- “Build Android Layouts in JetPack Compose”
- “Android Bottom Navigation Bar With Jetpack Compose”
Project Setup
Usually, in android, the keyboard appears when there are input fields on the screen.
In this compose example, we’ll use OutlinedTextField
to explore keyboard actions. We’ll have two input fields. One to indicate name
and the other one for amount
. We’ll have Scaffold
as root and then Column
to arrange the OutlinedTextFields
vertically. Have a look: