Friday, December 11, 2009

Hard Android vs Soft Keyboard

I'm now porting BlackBerry application to Android platform and had to use dialogs at this platform. You know, this is some of Dialog objects. Rather good popup windows, capable to carry some useful view payload. But...

I have encountered curious problem (not first, to be honest, during this project): if dialog shown, hidden and after that soft keyboard is shown - view will not be resized to make space for keyboard, instead keyboard will overlay on view.
So, there is possible situation, when editbox, which is located on bottom of view, will be obscured with keyboard. When it get focus, it will request self to be visible and view will be paned to make it visible. But with no way back, as view paned entirely!

I google'd and found this email (thanks to it's author, Oceanedge, which gived right digging direction). In this email written, that
android:windowSoftInputMode=adjustResize
will not help, but this is not correct.

It seems that main reason of my problem is that dialog sets "adjust pan" mode on window, while nobody setted "adjust resize" back again. So, problem was solved by adding code, which resets "adjust rezize" on activity window when dialog is dismissed:

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


So, this is solution for problem with resize view/window for keyboard after dialog pops up. Hope this will help anyone.