RecycleView(LinearLayoutManager 를 통 해)소프트 키 보드 를 표시 하고 외부 에 소프트 키 보드 를 숨 기 려 면 누 르 십시오.

1.fragment 의 레이아웃 은 Recycle View 를 사용 해 야 소프트 키보드 가 View 를 위로 올 릴 수 있 습 니 다.(외 부 는 FramLayout 용기)
 

            
        

    

  //     Edittext+TextView(  )          

    



    

    


2 activity 설정 필요 없 음

3.본론 으로 들 어가 소프트 키보드 보이 기
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
private void showInput(String hint) {
        rlImport.setVisibility(View.VISIBLE);
        editText.requestFocus();
        editText.setFocusable(true);
        editText.setHint(hint);
        imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
        //  imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    }

4 Recycle View 의 클릭 항목 아래쪽 이 Edittext 용기 의 맨 위 에 있 습 니 다.
 linearLayoutManager = new LinearLayoutManager(activity);
                countrySideAdapter = new CountrySideAdapter(rowsBeans);
                rvView.setLayoutManager(linearLayoutManager);

 //  
    private void comment(int position) {
         showInput("     ");
         final View itemCircle = linearLayoutManager.findViewByPosition(position);
         new Handler().postDelayed(() -> {
             int scrollLocation = getScrollLocation(itemCircle);
             rvView.smoothScrollBy(0, scrollLocation);
         }, 400);
    }

   public int getScrollLocation(View itemView) {
        int[] importLocation = new int[2];
        rlImport.getLocationOnScreen(importLocation);

        itemView.getHeight();
        int[] itemViewLocation = new int[2];
        itemView.getLocationOnScreen(itemViewLocation);
        return (itemViewLocation[1] + itemView.getHeight()) - importLocation[1];
    }

5 외부 클릭(소프트 키보드+아래쪽 rlImport 이외 의 부분)소프트 키보드 숨 기기
public void hideInputWindow(Activity context) {
        if (editText != null && editText.getWindowToken() != null) {
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        }
        rlImport.setVisibility(View.INVISIBLE);
    }

activity 에서 배포 사건 감청
 @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                View view = getCurrentFocus();
                if (isShouldHideInput(view, ev)) {
                    /*InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    if (imm.isActive()) {
                        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    }*/
                    Message msg = Message.obtain();
                    msg.what = Constans.HIDE_INPUT;
                    EventBus.getDefault().post(msg);
                }
                break;
        }
        return super.dispatchTouchEvent(ev);

    }

 private boolean isShouldHideInput(View view, MotionEvent ev) {
        // if (view != null && view.getId() == R.id.rl_import) instanceof EditText) {
        if (view != null && view.getId() == R.id.dynamicstate_comments_EditText) {
            int[] locationXY = new int[2];
            view.getLocationInWindow(locationXY);
            int leftX = locationXY[0];
            int rightX = locationXY[0] + view.getWidth();
            int topY = locationXY[1];
            int bottomY = locationXY[1] + view.getHeight();
            float downX = ev.getX();
            float downY = ev.getY();
            if (downY >= topY && downY <= bottomY) {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }

//frament     (           )

 @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(Message message) {
        switch (message.what) {
            case Constans.HIDE_INPUT:
                if (getUserVisibleHint()) {
                    hideInputWindow(activity);
                }
                break;
        }
    }

좋은 웹페이지 즐겨찾기