Android: Resize AlertDialog when keyboard is shown

There are times you have to show some text fields on the dialog, and when the keyboard pops up it becomes an absolute nuisance.

image

As you can see, the keyboard is covering the OK/Cancel buttons. In other cases it covers auto-complete or spinner items.

Thankfully, there's a quick and easy one liner that'll fix you right up. The last line is the one of particular interest to you.

AlertDialog d;
d = new AlertDialog.Builder(this);
...
d.create();

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

Make sure you have some sort of resizable element in the layout to accommodate for the reduction of screen space (such as a ScrollView).

p9wnQ
Don't worry Android keyboard, we still love you!

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog