Reputation: 13
i want to hide keyboard when user torches outside the Edit text but is not from activity but from fragment please any possible solution
Upvotes: 0
Views: 59
Reputation: 4446
Try to get EditTesxt focus status with setOnFocusChangeListener
and if it's not focused hide the keyboard:
editText.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
});
Upvotes: 1