Android Hide Soft Keyboard from EditText while not losing cursor

前端 未结 14 1944
日久生厌
日久生厌 2020-12-03 04:55

I\'ve come about as far as this which gets me halfway there, but not quite. I have a dialer Fragment that has all the usual Buttons to enter a numb

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 05:24

    EditText editText = (EditText)findViewById(R.id.edit_mine); editText.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.onTouchEvent(event);
            InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }                
            return true;
        }
    });
    

    ha... this is the correct way of doing...this job done... this gonna work !

提交回复
热议问题