android监听软键盘事件并获取键盘高度

【android监听软键盘事件并获取键盘高度】弱龄寄事外,委怀在琴书。这篇文章主要讲述android监听软键盘事件并获取键盘高度相关的知识,希望能为你提供帮助。

@Override public void onResume(){ super.onResume(); //获取当前屏幕内容的高度 getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { //获取View可见区域的bottom Rect rect = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); //避免重复事件 String keyboardStatus = String.format("%d%d%d",bottom,oldBottom,rect.bottom); if(keyboardStatus.equals(lastKeyboardStatus)){ return; } lastKeyboardStatus = keyboardStatus; if(bottom!=0 & & oldBottom!=0 & & bottom - rect.bottom < = 0){ HashMap< String,Object> data = https://www.songbingjia.com/android/new HashMap< String, Object> (); data.put("eventName","hide"); ImUtils.dispatch("keyBoardEvent",data); }else { HashMap< String,Object> data = https://www.songbingjia.com/android/new HashMap< String, Object> (); data.put("eventName","show"); data.put("height",bottom - rect.bottom); ImUtils.dispatch("keyBoardEvent",data); } } }); }

 

    推荐阅读