美文网首页
监听键盘弹起收回

监听键盘弹起收回

作者: 自然之秋 | 来源:发表于2017-12-22 10:17 被阅读46次
    344986770424649240.jpg

    评论——回复评论:走同一个编辑框

    recycleAdapter.setOnItemClickListener(new recycleAdapter.OnItemClickListener() {
    @Override
    public void onItemClick(View view, int position) {
    isHuifu = true;
    SPUtils.saveBoolean("isHuifu",true);
    mHuiFuCid = list.get(position).cid;
    showSoftInputFromWindow(activity, editContent);
    }
    });

    点击弹出指定EditText的 软键盘

    public static void showSoftInputFromWindow(Activity activity, EditText editText) {
    editText.requestFocus();
    InputMethodManager imn = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imn.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    }

    由于还要分别是点击回复还是直接评论弹出的,而且可能中间用户收起软键盘,因此要判断

    //获取屏幕高度
    int screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
    //阀值设置为屏幕高度的1/3
    final int keyHeight = screenHeight / 3;

        rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                if (oldBottom != 0 && bottom != 0 && (oldBottom - bottom > keyHeight)) {
                    LogUtils.e(TAG, "...监听到软键盘弹起..." + isHuifu);
                } else if (oldBottom != 0 && bottom != 0 && (bottom - oldBottom > keyHeight)) {
                    boolean isClick = SPUtils.getBoolean("isHuifu",false);
                    String strContent = newsDetailWriteComment.getText().toString().trim();
                    if (isClick){
                        if (TextUtils.isEmpty(strContent) ) {
                            isHuifu = false;
                            SPUtils.saveBoolean("isHuifu", false);
                            LogUtils.e(TAG, isClick+strContent+"...监听到软件盘关闭..." + isHuifu);
                        }
                    }
                }
            }
        });
    

    相关文章

      网友评论

          本文标题:监听键盘弹起收回

          本文链接:https://www.haomeiwen.com/subject/dtdtgxtx.html