By Shakil Ahmed, Android developer & software engineer
How to Fix the Keyboard Covering Your TextField in Jetpack Compose
Keyboard hiding your TextField after enableEdgeToEdge()? Here is the quick fix with imePadding and adjustResize, plus every other cause with before/after code.
If the keyboard is covering your TextField in Jetpack Compose, you are not alone. This is one of the most common problems I see in new Compose apps, and it got more common after Android made edge-to-edge the default. The good news: the fix is usually one or two lines. In this post I will show you the quick fix first, then every cause I know and how to solve it.
The Problem
You build a simple form or a chat screen. You tap a TextField near the bottom of the screen. The keyboard slides up and... it hides the field. You can't see what you are typing. Sometimes the send button is hidden too.
There is no crash and no error. Logcat shows nothing useful. The layout simply does not move.
This happens a lot with the default "Empty Activity" template in Android Studio, because the template calls enableEdgeToEdge() in onCreate():
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MyAppTheme {
LoginScreen()
}
}
}
With edge-to-edge, your app draws behind the system bars and behind the keyboard. Android gives you the keyboard size as an "inset", but it is your job to use it.
Note: If your app targets SDK 35 (Android 15) or higher, edge-to-edge is enforced on Android 15+ devices. If you target SDK 36 (Android 16), the old opt-out attribute
windowOptOutEdgeToEdgeEnforcementis deprecated and disabled on Android 16 devices. So "just turn off edge-to-edge" is no longer a real option. You need to handle insets.
Quick Fix (Try This First)
Do these two steps.
Step 1. In AndroidManifest.xml, add adjustResize to your activity:
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
...
</activity>
Step 2. Add Modifier.imePadding() to the container that holds your TextField:
Column(
modifier = Modifier
.fillMaxSize()
.imePadding() // push content above the keyboard
.padding(16.dp)
) {
Spacer(Modifier.weight(1f))
OutlinedTextField(
value = text,
onValueChange = { text = it },
label = { Text("Message") },
modifier = Modifier.fillMaxWidth()
)
}
Run the app again. In most cases the TextField now sits right above the keyboard, and it even animates smoothly with the keyboard.
If that worked, great. If not, keep reading. The cause is probably one of the cases below.
Why This Happens
Think of the screen like a room, and the keyboard like a big sofa that someone pushes in from the bottom.
In the old days (no edge-to-edge), Android would make the room smaller when the sofa came in. Your furniture moved up automatically.
With edge-to-edge, the room stays the same size. The sofa just sits on top of your furniture. Android tells you, "the sofa is 300 pixels tall," but you must move your furniture yourself.
That message is called the IME inset (IME = Input Method Editor, which is the keyboard). In Compose you read it with WindowInsets.ime, and the easiest way to apply it is Modifier.imePadding().
The official setup guide says adjustResize is what lets your app receive IME insets, so you can add padding when the keyboard appears. That is why the quick fix has two parts.
All Causes and How to Fix Them
1. No imePadding anywhere
This is the most common cause. Edge-to-edge is on, but nothing in your layout reacts to the keyboard.
Before:
Column(Modifier.fillMaxSize().padding(16.dp)) {
Spacer(Modifier.weight(1f))
TextField(value = text, onValueChange = { text = it })
}
After:
Column(
Modifier
.fillMaxSize()
.imePadding()
.padding(16.dp)
) {
Spacer(Modifier.weight(1f))
TextField(value = text, onValueChange = { text = it })
}
2. Scaffold innerPadding is not enough
Many beginners think Scaffold handles the keyboard. It does not. The Material 3 Scaffold gives you innerPadding for the system bars and your top/bottom bars, but the default content insets do not include the keyboard.
A second mistake is adding imePadding() next to innerPadding without telling Compose that the navigation bar space is already used. When the keyboard opens, you get a gap the size of the navigation bar between the keyboard and your field. That is double padding.
Before:
Scaffold(topBar = { TopAppBar(title = { Text("Chat") }) }) { innerPadding ->
Column(
Modifier
.padding(innerPadding)
.imePadding() // adds bottom space twice
) { /* ... */ }
}
After:
Scaffold(topBar = { TopAppBar(title = { Text("Chat") }) }) { innerPadding ->
Column(
Modifier
.fillMaxSize()
.padding(innerPadding)
.consumeWindowInsets(innerPadding) // "this space is already used"
.imePadding()
) { /* ... */ }
}
consumeWindowInsets(PaddingValues) tells the inset modifiers below it that some space is already handled. So imePadding() only adds the extra space the keyboard needs. If you are new to Scaffold, read my Scaffold and bottom navigation guide first.
3. Scrollable form with the wrong modifier order
For a long form (sign up, profile edit), you want the content to scroll when the keyboard is open. Modifier order matters here. If imePadding() comes after verticalScroll(), the padding is added inside the scroll content, not to the visible area.
Before:
Column(
Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.imePadding() // wrong place
.padding(16.dp)
) { FormFields() }
After:
Column(
Modifier
.fillMaxSize()
.imePadding() // first: shrink the visible area
.verticalScroll(rememberScrollState()) // then: scroll inside it
.padding(16.dp)
) { FormFields() }
A simple rule: apply insets to the viewport first, then make it scroll.
Tip: Modifiers run from top to bottom, like layers of clothing. Padding that comes earlier wraps everything after it.
4. Chat screen: LazyColumn with an input bar at the bottom
For a chat app, you want the message list to shrink and the input bar to sit on top of the keyboard. Put imePadding() on the parent, and give the list weight(1f).
Before:
Box(Modifier.fillMaxSize()) {
LazyColumn(Modifier.fillMaxSize()) { items(messages) { MessageRow(it) } }
MessageInput(Modifier.align(Alignment.BottomCenter))
}
After:
Column(
Modifier
.fillMaxSize()
.imePadding()
) {
LazyColumn(
modifier = Modifier.weight(1f),
reverseLayout = true // newest message at the bottom
) {
items(messages, key = { it.id }) { MessageRow(it) }
}
MessageInput(Modifier.fillMaxWidth())
}
Now the list takes all the free space, and the input bar always stays right above the keyboard. I use this same layout in my Gemini AI chat app tutorial. If you are new to lists, see LazyColumn for beginners.
Warning: The official docs warn that using
contentPaddingon aLazyColumnto keep the lastTextFieldabove the system bars can let the keyboard hide it. Use aSpacerwithModifier.windowInsetsBottomHeight(WindowInsets.systemBars)as the last item instead.
5. The focused field is in the middle of a long form
Sometimes padding is correct, but the focused field is still below the visible area. You want the screen to scroll to the field. Use BringIntoViewRequester:
val requester = remember { BringIntoViewRequester() }
val scope = rememberCoroutineScope()
OutlinedTextField(
value = address,
onValueChange = { address = it },
modifier = Modifier
.bringIntoViewRequester(requester)
.onFocusEvent { state ->
if (state.isFocused) {
scope.launch { requester.bringIntoView() }
}
}
)
The parent must be scrollable (for example verticalScroll). On older Compose versions this API needed @OptIn(ExperimentalFoundationApi::class). If Android Studio shows that warning, add the opt-in.
6. Missing or wrong windowSoftInputMode
If you set adjustPan or adjustNothing, or something in your theme overrides it, the IME insets may not reach your layout as you expect. adjustPan moves the whole window up instead of resizing it, which often pushes your top bar off screen.
Before:
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustPan" />
After:
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize" />
With edge-to-edge, adjustResize does not resize your Compose layout by itself anymore. Its job now is to make sure your app receives the IME insets. The actual moving is done by imePadding() or other inset modifiers.
7. Double padding from nested imePadding
If you add imePadding() on a parent and a child, you might expect double space. Compose is smart here: inset padding modifiers consume the insets they apply, so nested ones don't repeat the same space. But plain Modifier.padding() or Scaffold innerPadding does not consume insets. That is why cause 2 needs consumeWindowInsets.
If you see a strange gap above the keyboard, check for:
innerPadding+imePadding()withoutconsumeWindowInsetsnavigationBarsPadding()on a child andimePadding()on a parent, with plain padding in between- Hardcoded
padding(bottom = 48.dp)you added "to make it fit"
How to Prevent It
- Add
android:windowSoftInputMode="adjustResize"to every activity with text input, right when you create the project. - Decide one place per screen that handles the keyboard, usually the root
Columnof the screen. - With
Scaffold, use the patternpadding(innerPadding).consumeWindowInsets(innerPadding).imePadding(). - Put
imePadding()beforeverticalScroll(). - Test every screen with the keyboard open, in both gesture and 3-button navigation, and in landscape.
- Never hardcode a bottom padding to "fix" the keyboard. Keyboard height is different on every phone.
Tip: You can also use
Modifier.imeNestedScroll()(experimental) on a scrolling container. It lets users open and close the keyboard by scrolling at the bottom of the list, like many chat apps do.
Frequently Asked Questions
Do I still need adjustResize if I use enableEdgeToEdge()?
Yes. The official edge-to-edge setup guide recommends adjustResize so your app receives IME insets. Then imePadding() does the actual layout change.
Why does imePadding() do nothing in my app?
Usually adjustResize is missing, or the modifier is on the wrong composable (for example on the TextField itself inside a non-scrolling Box). Put it on the screen's root container.
Can I just disable edge-to-edge to fix the keyboard? Not really. Apps that target SDK 35+ are edge-to-edge on Android 15+, and for apps that target SDK 36 the opt-out flag is disabled on Android 16 devices. Handling insets is the long-term fix.
Why is there a big gap between the keyboard and my TextField?
That is double padding. Your layout adds the navigation bar space (from innerPadding or navigationBarsPadding()) and then the full keyboard height on top. Add consumeWindowInsets(innerPadding) before imePadding().
Summary
- Add
android:windowSoftInputMode="adjustResize"in the manifest - Add
Modifier.imePadding()to the screen's root container - With Scaffold:
padding(innerPadding)thenconsumeWindowInsets(innerPadding)thenimePadding() - For scrolling forms:
imePadding()beforeverticalScroll() - For chat:
Column+imePadding(),LazyColumnwithweight(1f), input bar at the bottom - For long forms: use
BringIntoViewRequesterto scroll the focused field into view - Remove hardcoded bottom paddings and check for double padding
If your screen still behaves strangely, the problem may be state, not layout. Check my posts on Compose buttons and state and debugging with Logcat. For the full details, read the official Window insets in Compose and Set up edge-to-edge guides on developer.android.com.
Related articles
Pick a photo, read its text on-device with ML Kit Text Recognition v2, and show blocks and lines in Jetpack Compose with a copy button.
Run AI directly on the phone with Gemini Nano and ML Kit GenAI APIs: privacy, offline use, device support, a Compose summarizer, cloud fallback and limits.
Build a secure AI chat in your Android app with Firebase AI Logic and Gemini: setup, App Check, model choice, streaming ViewModel, Compose UI and error handling.
Diagnose a faded Material 3 card, pair its foreground and background colors, and check the result in both light and dark mode.