我有一个包含EditText的片段用于输入,但现在我想在用户点击EditText之外的屏幕时关闭键盘.
我知道如何在一个活动中做到这一点,但对于片段来说似乎有所不同.
我在view.onTouchListener上调用此方法
public static void hideSoftKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
}
Run Code Online (Sandbox Code Playgroud)
有人有解决方案,谢谢