material-components / material-components/material-components-android

[MaterialAlertDialogBuilder] The background inset used by MaterialAlertDialog prevents it from panning up sufficiently when keyboard opens to prevent overlap

Open
#4,273 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Widget: Dialog
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

MRP.zip

Description: When using the MaterialAlertDialogBuilder to create a popup of sufficient size with an edit text, as soon as the edit text gains focus and the softboard appears, the popup does not slide up sufficiently to prevent an overlay but stops a significant amount of space from the top.

Expected behavior:
The popup should slide as far as it needs to to prevent overlap, as does a popup created with normal AlertDialog:
grafik

Source code: The issue is caused by the backgroundInset defined in MaterialAlertDialog.MaterialComponents.
Overriding the alertDialogStyle of the MaterialAlertDialog with a style that overrides those insets with 0 fixes the issue. However, this is still a bug because the top and bottom distance to the edges should be abandoned if space requires to.
The method loading them is

MaterialDialogs.getDialogBackgroundInsets(context, DEF_STYLE_ATTR, DEF_STYLE_RES);

Minimal sample app repro: ZIP appended

Android API version: API 28, API 31, seems to appear independently of API

Material Library version: 1.12.0

Device: Samsung, Pixel 7, does not matter as long as it is small enough

We also happily accept pull requests.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached MRP.zip minimal sample and the MaterialAlertDialogBuilder path that calls MaterialDialogs.getDialogBackgroundInsets(context, DEF_STYLE_ATTR, DEF_STYLE_RES). Reproduce the keyboard overlap on API 28 or 31, then compare the inset behavior with a normal AlertDialog. Done means the material dialog pans far enough to avoid the focused edit text being covered while preserving normal insets when space allows.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.