Android中监听软键盘显示状态实现代码
Android中监听软键盘显示状态实现代码
发布时间:2016-12-28 来源:查字典编辑
摘要:/**监听软键盘状态*@paramactivity*@paramlistener*/publicstaticvoidaddOnSoftKey...

/**监听软键盘状态 * @param activity * @param listener */ public static void addOnSoftKeyBoardVisibleListener(Activity activity, final OnSoftKeyBoardVisibleListener listener) { final View decorView = activity.getWindow().getDecorView(); decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); decorView.getWindowVisibleDisplayFrame(rect); int displayHight = rect.bottom - rect.top; int hight = decorView.getHeight(); boolean visible = (double) displayHight / hight < 0.8; Log.d(TAG, "DecorView display hight = " + displayHight); Log.d(TAG, "DecorView hight = " + hight); Log.d(TAG, "softkeyboard visible = " + visible); if(visible != sLastVisiable){ listener.onSoftKeyBoardVisible(visible); } sLastVisiable = visible; } }); }

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新安卓软件开发学习
热门安卓软件开发学习
编程开发子分类