androidandroid-virtual-keyboard

How to hide the virtual keypad by clicking outside of an EditText?


I am new to Android development. My requirement is that I want to hide the android virtual keypad when I click on the outside of an EditText widget. Please help.


Solution

  • To hide the virtual keyboard you can execute the following code:

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
    

    Simply put that code inside the onTouchDown() method of an OnTouchListener that is tied to the parent layout.