如何在EditText获取焦点时隐藏键盘

4

我希望editText框可被点击,以便用户可以滚动文本,但我不想让键盘出现。我已经尝试了所有这些方法,但它们都没能达到我的要求:

在XML中:

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

这将使其失效:

editText.setInputType(EditorInfo.TYPE_NULL); 

这仅适用于API 21及以上版本:

editText.setShowSoftInputOnFocus(false);

请跟随上面的链接:https://dev59.com/vHNA5IYBdhLWcg3wC5Xh - impathuri
尝试这个:https://dev59.com/wGox5IYBdhLWcg3wvW3X#8997725 - Anees Deen
3个回答

2

试试这个

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

1
使用这些代码行。
  EditText editText= (EditText) findViewById(R.id.editText);
  InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

0

设置一个编辑文本的触摸监听器。这将使编辑文本不可触摸,因为它被设置为返回 true。

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

编写一条语句,将其返回值设置为 false,从而允许用户触摸编辑文本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接