How to resize AlertDialog on the Keyboard display

Okay I have a AlertDialog box with approximately 10 controls (text and textview) on it. These controls are in a scrollview with alertdialog, plus I got 2 buttons positive and negative. The issue I have is when the soft keyboard pops up the two buttons are hidden behind the keyboard.

I was looking for something like redraw function on my inner View or the dialog box.

  • appcompat show progress in action bar causes NPE
  • Can I set the home icon of my actionbar using styles.xml?
  • Change font size in ListView - Android/Eclipse
  • hierarchy is not working for my device
  • Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease'
  • Testing ViewPager with Espresso. How perfom action to a button of an Item?
  • If any one has any idea please help. Below is the screen shot of what I am talking about.

    enter image description here

    Related posts:

    using ContentProviderClient vs ContentResolver to access content provider
    webviewglue nativedestroy view
    Android Proguard with external jar
    Custom Android views with Kotlin
    Is it possible to dither a gradient drawable?
    Add multiple custom views to layout programmatically
  • How do I set an ImageViews source programmatically in Android?
  • ProGuard can cause incorrect calculations
  • Why google map v2 suddenly crashed by java.lang.NullPointerException: Attempt to get length of null array?
  • Quick search on filename Android studio
  • Need code example on how to run an Android service forever in the background even when device sleeping, like Whatsapp?
  • Fragment methods: attach(), detach(), remove(), replace(), popBackStack()
  • 6 Solutions collect form web for “How to resize AlertDialog on the Keyboard display”

    If your dialog was an activity using one of the Dialog themes you could effect this behavior by setting the adjustResize flag for the windowSoftInputMode parameter of the activity.

    I’m using:


    I think you can still use this flag with regular dialogs, but I’m not sure how to apply it. You may have to create your AlertDialog with a custom theme that inherits the right parent theme and also sets that flag, or you might have to use ContextThemeWrappers and stuff.

    Or maybe you can just use Window#setSoftInputMode.


    I’ve found a best way to handle this. Because this is a dialog, So the code “alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);” doesn’t work very well.

    Besides this code, you must set a dialog style for this dialog. The style should like below:

    <style name="DialogStyle" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
        <item name="android:windowFullscreen">false</item>

    NOTICE that the attribute “parent” is “Theme.Black.NoTitleBar.Fullscreen” like a activity’s style. and the attribute “android:windowFullScreen” should be false.

    Now, the dialog will be resized when the soft keyboard toggled.

    maybe you don’t need to resize Dialog

    add android:imeOptions=”actionNext” to EditText(all but last) (it will add “Next” button to the keyboard – go to next EditText)

    and add android:imeOptions=”actionDone” to last EditText (“Done” button – hide keyboard)

    now user should be able to click buttons

    if you’re creating textboxes in code use EditText#setImeOptions function


    Are you forced to have it as a popup? The popup looks so large, that you may just want to have it as a separate activity. In general, popups are used to provide a brief question or statement with a few options, not a full blown data entry form. Since you can’t see much behind the large popup, you’re not exposing any underlying controls anyways.

    to show keyboard immediately and adjust size:

    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    Nothing worked for me except adjustPan

    as per the documentation

    The activity’s main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

    So just simply use it in your onCreate() or onCreateView() method like:


    Or simply put android:windowSoftInputMode="adjustPan" in manifest for the Activiry in which we are playing with dialogs

    and use android:windowSoftInputMode="adjustResize|stateHidden" in each edittext which will help the user to navigate to next textbox easily.

    Point to remember

    Never use MATCH_PARENT to make the dialog full screen as adjustPan will not work here. If anyone wants to make the dialog to fit the screen, just use points till 0.96 (not more than this) for the height, so the keyboard will properly reach to the edittext. I did like below :

    public void onStart()
        Dialog dialog = getDialog();
        if (dialog != null)
            //int height = ViewGroup.LayoutParams.MATCH_PARENT;
            int width = ViewGroup.LayoutParams.MATCH_PARENT;
            Display display = getActivity().getWindowManager().getDefaultDisplay();
            Point size = new Point();
            //int width = (int)(size.x * 0.96);
            int h = (int)(size.y * 0.96);
            dialog.getWindow().setLayout(width, h);

    Look, If I will use the total height (MATCH_PARENT) then soft_keyboard will squize the dialog. But if I will use points for the height (here 0.96 which is almost near to match_parent), then it will properly work.

    Hope it will help someone 🙂

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.