How can I get the height of virtual keyboard in Android? Is it possible?
I try to get it from the main window, but it gives me full height of the application. But I
If you don't want android:windowSoftInputMode="adjustResize" in your app.
You can try something like this:
any_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int height = main_layout.getHeight();
Log.w("Foo", String.format("layout height: %d", height));
Rect r = new Rect();
main_layout.getWindowVisibleDisplayFrame(r);
int visible = r.bottom - r.top;
Log.w("Foo", String.format("visible height: %d", visible));
Log.w("Foo", String.format("keyboard height: %d", height - visible));
}
});