/**监听软键盘状态 * @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; } }); }
Android에서 소프트 키보드 표시 상태를 모니터링하는 코드와 관련된 더 많은 기사를 보려면 PHP 중국어 웹사이트를 주목하세요!