Keyboard hiding EditTexts in Fragments

I have tried this code and resolve my issue.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

You can try to put this in onActivityCreated of your fragment:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

This should not make the keyboard upon loading or starting of your activity with fragment.


Try to call InputMethodManager.hideSoftInputFromWindow() during your fragment's onActivityCreated() function mentioned in this SO answer?

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    AppUtil.hideKeyboard(getActivity(), getView());
}

where hideKeyboard() looks like this

public static void hideKeyboard(Activity activity, View viewToHide) {
    InputMethodManager imm = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
}

Try to use WindowsSoftInputMode as adjustpan only.

For ex:

android:windowSoftInputMode="adjustPan"