I need to know when the user touches/taps/clicks the edittext in my activity.
How can I do this without interrupting the events, so the keypad still displays properly?
(And I need to know about it before the OS displays the keypad...if possible)
This example demonstrates how do I hide soft keyboard on android after clicking outside edittext. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus. This goes in your activity or fragment or wherever you have the EditTexts.
The most reliable way to do this is using UI. setReadOnly(myEditText, true) from this library. There are a few properties that have to be set, which you can check out in the source code.
txtEdit.setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View view, MotionEvent motionEvent) {
// your code here....
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With