How to hide keyboard when editText has focus

I want the editText window to be clickable so that the user can scroll the text, but I don't want the keyboard to appear. I've tried all of these, but they don't do what I want:

In XML:

android:editable="false"
android:windowSoftInputMode="stateAlwaysHidden"
android:inputType="none"

      

This disables it:

editText.setInputType(EditorInfo.TYPE_NULL); 

      

This only works with API 21 and above:

editText.setShowSoftInputOnFocus(false);

      

+3


source to share


3 answers


try it



<EditText
        android:id="@+id/et_file_url"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="none"
        android:lines="1"
        android:textIsSelectable="true" />

      

+2


source


Use these lines of code



  EditText editText= (EditText) findViewById(R.id.editText);
  InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

      

0


source


Set edit text on touch listener. This will make the edit text intact because it is set to return true.

   EditTextHere.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
          return true;
        }
    });

      

Make an expression that it will allow the user to touch the edit text, returning it to false.

0


source







All Articles