/**监听软键盘状态 * @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
android 软键盘监听、android 软键盘的监听、js 监听android软键盘、android 软键盘状态、android 软键盘的状态,以便于您获取更多的相关知识。
时间: 2024-10-03 05:49:46