Sources of the problem

Recently, the publisher encountered a nauseating problem: EditText in RecyclerView was blocked by a soft keyboard, which had been working all morning.

There's only one EditText in a single Item, and it's perfectly okay to pop up a soft keyboard.

But one of my Item s has an Image View on top and an EditText on the bottom, like this:

          

This user experience is super bad. It's not about Windows Soft Inout Mode.

After thinking about it, I also checked some information. I can only monitor the pop-up and shutdown of the soft keyboard.

Code:

        getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                mImgKeyboard.setImageResource(KeyboardUtils.isSoftShowing(ForumsPublishPostActivity.this)
                        ? R.mipmap.jianpan_down_ico : R.mipmap.jianpan_ico);

                // Visible area except soft keyboard
                Rect rect = new Rect();
                getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
                // Calculate the remaining height: Except the height of the status bar, the height of topBar, the height of bottomBar and the height of keyboard.
                int invisibleHeight = rect.bottom
                        - ViewUtils.getSystemBarHeight(ForumsPublishPostActivity.this)
                        - ViewUtils.dp2px(ForumsPublishPostActivity.this, 44)
                        - ViewUtils.dp2px(ForumsPublishPostActivity.this, 45);

                // Calculate the distance between the EditText described by the clicked image and the top of RecyclerView
                View etDescView = mRecyclerview.getLayoutManager().findViewByPosition(mAdapter.etFocusPosition);
                if (etDescView != null) {
                    int focusViewTop = etDescView.getTop();
                    int itemHeight = etDescView.getHeight();

                    int differ = focusViewTop + itemHeight - invisibleHeight;
                    if (differ > 0) {
                        // The point at which RecyclerView scrolls the difference
                        mRecyclerview.scrollBy(0, differ);
                    }
                }

            }
        });