Android: Disable soft keyboard at all EditTexts

2020-01-25 01:17发布

I am working on a dialog at Android with a few EditTexts. I've put this line at the onCreate() in order to disable the soft keyboard:

Keypad.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

The problem is that it works only when the dialog appear and doing nothing. When I move to the next EditText, the keyboard appears and not going down.

Does anybody have an idea how to solve this issue?

13条回答
姐就是有狂的资本
2楼-- · 2020-01-25 01:29

Its been some time since this post, but here is a simple method which worked for me: in the xml, in the EditText properties, do: android:focusable="false". Now the keyboard will not popup even if the user clicks on it. This is useful if you are providing your own keypad.

查看更多
Deceive 欺骗
3楼-- · 2020-01-25 01:33

by set EditText focusable->false, keyboard will not opened when clicked

<EditText
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:focusable="false" />
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-01-25 01:34

If you put the textViews in the view group you can make make the view get the focus before any of its descendants by using this:

view.setDescendantFocusability(view.FOCUS_BLOCK_DESCENDANTS);
查看更多
别忘想泡老子
5楼-- · 2020-01-25 01:37
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edSearch.getWindowToken(), 0);
查看更多
狗以群分
6楼-- · 2020-01-25 01:37

You can do that:

textView.setOnClickListener(null);

It will disable the keyboard to the textView and the click will not work anymore.

查看更多
Evening l夕情丶
7楼-- · 2020-01-25 01:39

Call TextView.setShowSoftInputOnFocus(false). This method is documented since API level 21, but it's already there since API level 16 (it's just hidden from JavaDoc). I use it with API level 16 in an AlertDialog in combination with dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN).

In API level 14, there is a hidden method setSoftInputShownOnFocus() which seems to have the same purpose, but I have not tested that.

The advantage over InputType.TYPE_NULL is, that all the normal input types can be used (e.g. for password input) and the touch event positions the cursor at the correct spot within the text.

查看更多
登录 后发表回答