private boolean isKeyboardShown(View rootView) {
final int softKeyboardHeight =100;
Rect r =new Rect();
rootView.getWindowVisibleDisplayFrame(r);
DisplayMetrics dm = rootView.getResources().getDisplayMetrics();
int heightDiff = rootView.getBottom() - r.bottom;
return heightDiff > softKeyboardHeight * dm.density;
}
private void registerKeyboardListener() {
final View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (isKeyboardShown(rootView)) {
bean.setInput(View.VISIBLE);
}else {
bean.setInput(View.GONE);
}
}
});
}
网友评论