0

Everytime I try to select a text,it opens the keyboard.How can I prevent this?

Evander
  • 76
  • 6
  • 1
    check [this question](https://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup?rq=1), the solution should be the same – isaaaaame Jan 24 '19 at 14:03

2 Answers2

1

Try

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
ManxDev
  • 98
  • 2
  • 12
1

You need to hide keyboard when click on edit text :

mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if ( hasFocus )
            {
                hideKeyBoard();
            }
        }
    });

and hideKeyboard method :

private void hideKeyBoard()
{
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        if( imm != null )
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
Kévin Giacomino
  • 487
  • 4
  • 11