android监听软键盘隐藏
2017-09-08 17:42
281 查看
从网上看到的是根据根布局的高度变化来监听软键盘的显示和隐藏,但是如果设置了adjustpan即根布局高度始终不变的时候是无效的,搜了好长时间才找到解决方法。
//获取到根布局,这个根布局和setContenView的布局不一样。 rootView = getWindow().getDecorView().findViewById(android.R.id.content); //然后设置布局的监听 rootView.getViewTreeObserver().addOnGlobalLayoutListener(this); //让本类继承接口实现方法 @Override public void onGlobalLayout() { if(isKeyboardShown(rootView)){ }else { // Log.e(TAG, "onGlobalLayout: " ); // mImmersionBar.fixMarginAtBottom(true).init(); } } //这个是最主要的方法,根据根布局可视的高度来判断软键盘的显示和隐藏 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; }
相关文章推荐
- Android 键盘使用一(监听弹出隐藏)
- Android监听软键盘显示与隐藏状态来动态改变布局
- Android 软键盘显示和隐藏监听
- android 监听软键盘弹出和隐藏和4.4系统沉浸式通知栏冲突解决
- Android关于adjustResize无效,监听软键盘的隐藏显的解决方案
- android 监听键盘的弹起和隐藏
- Android监听键盘的显示和隐藏
- Android监听软键盘弹起隐藏
- android监听键盘弹出or隐藏方法
- android 监听软键盘按键的三种方式--和--隐藏系统键盘
- android学习,通过监听焦点,来进行类似监听软键盘弹出隐藏的功能
- Android 监听软键盘显示隐藏
- android 监听键盘显示或者隐藏
- Android监听键盘显示和隐藏
- 监听android键盘弹出隐藏
- android 监听软键盘弹起和关闭状态与点击空白区域软键盘隐藏
- Android监听系统输入法键盘弹出显示与隐藏事件
- Android监听软键盘弹出与隐藏的两种方法
- android软键盘弹出隐藏的监听
- Android监听键盘显示和隐藏