Android Hide Soft Keyboard from EditText while not losing cursor

前端 未结 14 1943
日久生厌
日久生厌 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 05:24

    This worked for me:

            // Update the EditText so it won't popup Android's own keyboard, since I have my own.
        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;
            }
        });
    

提交回复
热议问题