/**监听软键盘状态
*@paramactivity
*@paramlistener
*/
publicstaticvoidaddOnSoftKeyBoardVisibleListener(Activityactivity,finalOnSoftKeyBoardVisibleListenerlistener){
finalViewdecorView=activity.getWindow().getDecorView();
decorView.getViewTreeObserver().addOnGlobalLayoutListener(newViewTreeObserver.OnGlobalLayoutListener(){
@Override
publicvoidonGlobalLayout(){
Rectrect=newRect();
decorView.getWindowVisibleDisplayFrame(rect);
intdisplayHight=rect.bottom-rect.top;
inthight=decorView.getHeight();
booleanvisible=(double)displayHight/hight<0.8;
Log.d(TAG,"DecorViewdisplayhight="+displayHight);
Log.d(TAG,"DecorViewhight="+hight);
Log.d(TAG,"softkeyboardvisible="+visible);
if(visible!=sLastVisiable){
listener.onSoftKeyBoardVisible(visible);
}
sLastVisiable=visible;
}
});
}