CallMeDeftsu4
CallMeDeftsu4

Reputation: 127

Soft keyboard keeps popping up

I've implemented an app with a NavigationDrawer and some Fragments. But everytime I change Fragment with the NavigationDrawer, the soft keyboard keeps popping up, even if there's no EditText on the screen.

How can I solve this?

Upvotes: 0

Views: 189

Answers (4)

Kelsie Lewis
Kelsie Lewis

Reputation: 1

View view = this.getCurrentFocus();

if (view != null) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

This helped me out. I hope it works.

Upvotes: 0

Masum
Masum

Reputation: 4969

Add this line of code in your activity

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

And try with adding to fragment also.

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

Upvotes: 1

Quick learner
Quick learner

Reputation: 11467

Try This in your BaseActivity or Main Activity

 View view = this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

Upvotes: 0

Cory Roy
Cory Roy

Reputation: 5619

Have you tried adding this to your manifest for the activity:

android:windowSoftInputMode="stateHidden"

Upvotes: 1

Related Questions