I have three EditText fields in action, for two of which the usual input methods (hard keys, standard soft keyboard) are fine. But for one of the EditText fields, I want to send soft input only from a custom keyboard view. Therefore, in essence, I want the default soft keyboard for this EditText not to display. I tried adding onTouchListeners and onFocusChange listeners for EditText with partial success like this:
public boolean onTouch(View v, MotionEvent event) { v.requestFocus(); imm.toggleSoftInput(0, 0); return true; } public void onFocusChange(View v, boolean hasFocus) { InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive(v)) { imm.toggleSoftInput(0,0); } }
But I did not reach a final decision because
1) By default, the soft keyboard always flashes briefly before the listener hides it.
2) in some cases, for example, moving the focus in EditText using the keyboard arrow keys sometimes sets the default soft keyboard that is visible.
etc.
So I would love to find an easy way to tell Android to never show the standard soft keyboard for this particular EditText. I would not want to extend EditText and start redefining the material, as the functionality of EditText is perfect for me - I just want the standard soft keyboard not to display.
I spent days trying to figure it out. Some topics (including some of them) found using google are halfway trying this problem, but so far I have not found a single fully functional solution.
EDIT:
I'm really starting to get annoyed. I decided that I could not use EditText, but any other kind that would do the job. It turns out that it is very difficult to get rid of this soft keyboard. It even appears when I use hard keys to move the focus from the EditText to the button! Why should a soft keyboard appear on the screen on every freakin View that has focus? Even when I explicitly say inputType = "none"? How to disable this soft keyboard * ? Below is the xml for the button - let this be used as an example:
<Button android:id="@+id/OkButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="none" android:paddingRight="5mm" android:paddingLeft="5mm" android:layout_below="@id/Volume" android:layout_alignParentLeft="true" android:text="OK"/>
EDIT2:
I have a solution that seems to work. First, I delay InputMethodManager:
this.imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
and I set OnClickListener, OnTouchListener and OnFocusChange listener all will call the following method when I want the EditText to be focused and my custom KeyboardView is visible, hiding the soft input by default:
private boolean makeActive(View v) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); EditText e = (EditText) v; int iType = e.getInputType(); e.setInputType(InputType.TYPE_NULL); e.requestFocus(); showKb(); e.setInputType(iType); return true; }