I have an activity that is using "adjustPan" as its resize config, and I need to calculate keyboard height without using "adjustResize" because I need to keep some views as fullscreen (which means they should stay where they are, the keyboard should hide them), and position a view right above the keyboard. Our application has a message button and I open the keyboard via the button click. When it happens, I use an OnGlobalLayoutListener and use "getWindowVisibleDisplayFrame" method to get the keyboard's height. Here is some code for it:
private void message()
{
InputMethodManager methodManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (methodManager != null && !isKeyboardOpen)
{
methodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
if (bottomCoordinate == 0)
{
RelativeLayout layout = findViewById(getFullScreenContainerId());
layout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Rect r = new Rect();
layout.getWindowVisibleDisplayFrame(r);
bottomCoordinate = r.bottom - r.top;
translateMessageView(bottomCoordinate);
}
});
}
else
translateMessageView(bottomCoordinate);
isKeyboardOpen = true;
}
}
"translateMessageView" basically sets the view's Y coordinate to "bottomCoordinate - view.getHeight()". This works good up until the autocorrect part of the soft keyboard applications becomes visible. Apparently "getWindowVisibleDisplayFrame" method doesn't seem to add autocorrect part of the view or "onGlobalLayout" method is not called when soft keyboard's autocorrect part shows up, and the positioned view stays under it which makes it half-visible. I need to be able to adjust its position again, so what should I do? What is the correct approach for this? Any suggestion is valuable, thank you.