TechBuzzPro

How to Move Layout Up When Soft Keyboard Shows on Android

· 6 min read · Phones & Tablets

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To keep a layout visible when the soft keyboard appears on Android, set the activity's windowSoftInputMode to adjustResize in the manifest, or call WindowCompat.setDecorFitsSystemWindows(window, false) and use the WindowInsetsCompat API to apply bottom padding equal to the IME inset. The first approach is the quickest for classic View-based layouts; the second is the current recommendation for edge-to-edge apps and Compose. The keyboard itself does not move your layout unless you tell the window how to react, so the fix is almost always a window flag or an inset listener, not a layout tweak.

What You'll Need

  • Android Studio with a project that targets a recent SDK (API 30 or higher is a safe baseline).
  • Access to your app's AndroidManifest.xml and the activity or composable that hosts the form or list.
  • A device or emulator running Android 11 or newer for testing, since older versions handle insets differently.
  • Basic familiarity with XML layouts or Jetpack Compose, depending on which UI toolkit your app uses.

Step-by-Step

  1. Decide which window mode you need. For a classic View-based screen where the whole layout should shrink above the keyboard, use adjustResize. For a scrolling form where only the focused field needs to stay visible, adjustPan can work but often hides content, so adjustResize is the safer default. For edge-to-edge apps, neither flag is enough on its own; you must handle insets manually.
  2. Set the soft input mode in the manifest. Open AndroidManifest.xml, find the <activity> tag for the screen, and add android:windowSoftInputMode="adjustResize". If your app uses a single activity with fragments, set it on that activity. Labels and attribute names can differ slightly between Android versions and OEM skins, but windowSoftInputMode is stable across current releases.
  3. Remove fullscreen flags that block resizing. Check the activity's theme and code for WindowManager.LayoutParams.FLAG_FULLSCREEN or a theme that sets windowFullscreen to true. Fullscreen windows ignore adjustResize on many devices, so the keyboard simply overlays the layout. Switch to a normal theme or handle insets explicitly.
  4. Test with the keyboard open. Run the app, tap a text field near the bottom of the screen, and watch whether the layout shrinks or the field stays covered. On some devices the keyboard opens as a floating window, which does not trigger resize; test with the standard docked keyboard first.
  5. For edge-to-edge apps, stop fitting system windows. In your activity's onCreate, call WindowCompat.setDecorFitsSystemWindows(window, false). This tells the system your app will draw behind the status and navigation bars and handle the keyboard inset itself.
  6. Apply the IME inset as bottom padding. Use ViewCompat.setOnApplyWindowInsetsListener on your root view. Inside the listener, read WindowInsetsCompat.Type.ime() and set the view's bottom padding to that value, then return the insets. This pushes the content up by exactly the keyboard height and restores it when the keyboard closes.
  7. For Compose, use imePadding or WindowInsets.ime. Apply Modifier.imePadding() to the container that should move, or read WindowInsets.ime and convert it with asPaddingValues(). Make sure the activity is edge-to-edge with enableEdgeToEdge() so the inset values are reported correctly.
  8. Wrap scrollable content in a scroll container. If the form is taller than the remaining space, place it inside a ScrollView (Views) or a verticalScroll modifier (Compose). Without scrolling, adjustResize shrinks the layout but the focused field can still be clipped.
  9. Request focus and scroll to the field. When a field gains focus, call requestRectangleOnScreen on the view or use BringIntoViewRequester in Compose so the field is not just visible but actually on screen above the keyboard.
  10. Verify on multiple API levels and keyboards. Test with the default keyboard and at least one third-party keyboard, since their reported inset heights can differ. Also test rotation and split-screen mode, where the available height changes.

Common Mistakes

  • Setting adjustResize but leaving a fullscreen theme in place, so the flag has no effect.
  • Using adjustPan for a long form: the window pans just enough to show the cursor, but the top of the form scrolls off screen and users lose context.
  • Applying the IME inset to the wrong view. Padding must go on the root container, not on the text field itself, or the layout will double-shift.
  • Forgetting to consume or return the insets, which causes the padding to be applied repeatedly and the layout to jump.
  • Assuming the keyboard height is fixed. It changes with keyboard type, language, and whether suggestions are shown.
  • Testing only on an emulator with a hardware keyboard enabled, where the soft keyboard may never appear.

Tips

  • Use WindowInsetsCompat.Type.ime() rather than a hardcoded pixel value; keyboard heights vary by device and user settings.
  • Keep the bottom navigation bar visible by adding the navigation bar inset to the IME inset only when the keyboard is open.
  • In Compose, combine imePadding() with navigationBarsPadding() on the same container to avoid gaps.
  • If your screen has a bottom button, pin it above the keyboard by applying the IME inset as bottom padding to the button's parent, not the whole screen.
  • Use the Android Studio Layout Inspector to check whether the keyboard inset is being reported as zero, which usually means the window is still fitting system windows.

Troubleshooting

If the layout still does not move, work through these checks in order. First, confirm the manifest change is on the correct activity and that no theme overrides it. Second, remove any fullscreen or translucent window flags. Third, if you are on edge-to-edge, verify that setDecorFitsSystemWindows(false) runs before the view is created. Fourth, check that your inset listener is attached to the root view and that it returns the insets rather than consuming them silently. Fifth, test with a different keyboard; some keyboards report an inset of zero when they are in floating mode. Sixth, if the layout moves but the field is still hidden, add a scroll container and request the rectangle on screen. Finally, if nothing works, temporarily set adjustPan to confirm the keyboard is being detected at all; if adjustPan works and adjustResize does not, the problem is almost always a fullscreen flag or a missing inset handler.

Frequently Asked Questions

Why does adjustResize not work on my device?

Most often because the activity uses a fullscreen theme or flag, or because the app is edge-to-edge and has not applied the IME inset manually. Remove fullscreen flags first, then add an inset listener.

Should I use adjustPan or adjustResize?

Use adjustResize for forms and any screen where the whole layout should stay visible. adjustPan only pans the window enough to show the cursor and can hide the rest of the screen.

How do I handle the keyboard in Jetpack Compose?

Enable edge-to-edge with enableEdgeToEdge(), then apply Modifier.imePadding() or read WindowInsets.ime on the container that should move.

Can I detect the keyboard height without insets?

Not reliably. The official way is the WindowInsets API. Older tricks based on global layout listeners are fragile and break with gesture navigation and floating keyboards.

Does the keyboard inset include the navigation bar?

No. The IME inset is separate from the navigation bar inset. Add them together only when you want the layout to clear both.

Why does the layout jump when the keyboard opens?

Usually because the inset listener applies padding on every call without resetting it, or because two containers both apply the same inset. Apply the inset once, on the root container.