如何查找软键盘可见或不可见的事件。我想在键盘出现并且按下它消失时捕捉事件。我能够捕捉完成按钮按下的事件并且它工作正常。
任何帮助表示赞赏。提前致谢。
final View activityRootView = rellayLoginParent;
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
Rect r = new Rect();
// r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
//MyLog.w("height difference is", "" + heightDiff);
if (heightDiff > 100)
{ // if more than 100 pixels, its probably a keyboard...
/*isKeyBoardVisible = false;
linlayAdLayout.setVisibility(View.GONE);*/
Log.e("Keyboard Visibilitty","Visible");
if(lytAppHeader.getVisibility() == View.VISIBLE)
{
lytAppHeader.setVisibility(View.GONE);
}
}
else
{
//linlayAdLayout.setVisibility(View.VISIBLE);
Log.e("Keyboard Visibilitty","InVisible + Gone");
if(lytAppHeader.getVisibility() == View.GONE)
{
lytAppHeader.setVisibility(View.VISIBLE);
}
}
}
});