How to prevent the virtual keyboard from appearing with a long press on the EditText Widget?

I have an EditText widget in my application that I installed read-only, and I want to know when the user clicks on it for a long time. I do not want the virtual keyboard to pop up if the user clicks on this widget.

To stop the virtual keyboard from appearing, I use the following:

Text EditText = (EditText) findViewById (R.id.editText01); editText.setClickable (false);

This works, but I cannot receive messages with a long press if I use OnLongClickListener ().

Does anyone know how I can prevent a pop-up keyboard from appearing, but still receive events with a long press?

Thanks.

EDITED: I actually tried the first two answers posed to this question, and none of them worked. What I ended up doing was for the EditText widget, I used the following:

editText.setInputType(InputType.TYPE_NULL);
editText.setCursorVisible(false);
editText.setOnLongClickListener(mOnLongClickListener);

Calling the setInputType () method disables clicks for the widget. In the setOnLongClickListener () method, all events with a long click on the widget will be processed, and I return the true value from this procedure, which basically consumes an event with a long click. So now I have an EditText widget that will not have a virtual keyboard popup when pressed, but a long press on this widget will call my listening method.

+2
source share
2 answers
button.setOnLongClickListener (View.OnLongClickListener l(){

//override the method  

//then do this

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
});
+2
source

Try using this and the available options.

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

, , , EditText. , OnCreate(). ".SOFT_INPUT_STATE_ALWAYS_HIDDEN"

+1

Source: https://habr.com/ru/post/1610891/


All Articles