如何在 editText 处于焦点时隐藏键盘

How to hide keypad when editText is in focus

我希望 editText 框可以单击,以便用户可以滚动浏览文本,但我不希望键盘出现。 我已经尝试了所有这些,但他们没有做我想做的事:

在XML中:

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

这将禁用它:

editText.setInputType(EditorInfo.TYPE_NULL); 

这仅适用于 API 21 岁及以上:

editText.setShowSoftInputOnFocus(false);

使用这几行代码

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

试试这个

<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" />

在触摸侦听器上设置编辑文本。这将使编辑文本不可触摸,因为它设置为 return true.

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

通过return将其设置为 false 来声明允许用户触摸编辑文本。