I have a fragment containing an EditText for input, but now I want to close the keyboard when the user clicks on the screen outside of the EditText.
I know how to do this in an activity, but it seems to be different for fragments.
i am calling this method on view.onTouchListener
public static void hideSoftKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
}
anyone have solution, thanks
In case of Fragment use below code
Apply this code and call dispatchTouchEvent(); method
You can also do like this
Hope it help!
i just overrided dispatchTouchEvent() Method in all the fragments of the activity.
and set property in every XML of fragment in Main Layout
You could use this method is working fine for me. Just pass the reference of the root element of your layout like this
code for the setupUI is below..
In the parent Activity of the fragment override the following method:
And in the layout of the fragment use this attribute:
Hope this will help you.
If you want Touch outside of editText then Keyboard hide automatic so use this code