Search code examples
androidviewresizeandroid-alertdialogandroid-softkeyboard

How to resize AlertDialog on the Keyboard display


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. Below is the screen shot of what I am talking about.

enter image description here


Solution

  • 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:

    android:windowSoftInputMode="adjustResize|stateHidden"
    

    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.

    alertDialog.getWindow().setSoftInputMode(
        WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);