Case 1: if you want to close the keyboard when opening a dialog fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView( inflater, container, savedInstanceState );
Case 2: If you want to close the keyboard when choosing auto-complete text or any other type of text editing, use a simple
public static void hideDialogFragmentKeyboard(Context context,View view) { view.postDelayed(new Runnable() { @Override public void run() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }, 100); }
I think it will work
Dipesh
source share