亲宝软件园·资讯

展开

Android监听软键盘显示状态 Android中监听软键盘显示状态实现代码

人气:0
想了解Android中监听软键盘显示状态实现代码的相关内容吗,在本文为您仔细讲解Android监听软键盘显示状态的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,监听软键盘显示状态,下面大家一起来学习吧。
/**监听软键盘状态
   * @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;
      }
    });
  }

加载全部内容

相关教程
猜你喜欢
用户评论