Created
November 19, 2014 11:58
-
-
Save devrath/fd62e68c2bc2319a787a to your computer and use it in GitHub Desktop.
Hide the keyboard onClick of outside click of edit text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REFER: http://stackoverflow.com/a/19828165/1083093 | |
//Step1: Add in the root of the layout, if its a scrollview add to the parent(eg:linearlayout) not the scroll view | |
android:clickable="true" | |
android:focusableInTouchMode="true" | |
//Step2: Add this method | |
public void hideKeyboard(View view) { | |
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE); | |
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); | |
} | |
//Step3: Add this setOnFocusChangeListener event in onStart for the editText | |
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() { | |
@Override | |
public void onFocusChange(View v, boolean hasFocus) { | |
if (!hasFocus) { | |
hideKeyboard(v); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cbcvbcb