@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 = new HashMap<String, Object>();
data.put("eventName","hide");
ImUtils.dispatch("keyBoardEvent",data);
}else {
HashMap<String,Object> data = new HashMap<String, Object>();
data.put("eventName","show");
data.put("height",bottom - rect.bottom);
ImUtils.dispatch("keyBoardEvent",data);
}
}
});
}