Android反射获取键盘高度判断键盘是否显示

    public boolean getKeyBoardIsShow(Context context){
       try {
          InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
          Method method = im.getClass().getDeclaredMethod("getInputMethodWindowVisibleHeight");
          method.setAccessible(true);
          int height = Integer.parseInt(method.invoke(im).toString());
          if(height > 0){
              return true;
          }
       }catch (Throwable e){
           Log.e("Error",Log.getStackTraceString(e));
       }
       return false;
    }

猜你喜欢

转载自blog.csdn.net/a940659387/article/details/122436138