dor506
dor506

Reputation: 5404

Hiding keyboard before activity is visible

I have an activity (A) which launches activity (B).

Activity A using keyboard in some situations.

I want to hide the keyboard (if it is showed) before B is launched.

However,when A launches B, the keyboard is still visible for a just seconds after B is already visible.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
startActivity(..); //starts Activity B

How can I hide the keyboard before B is called? thanks!

Upvotes: 4

Views: 3072

Answers (2)

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

add in your AndroidManifest.xml for you activity android:windowSoftInputMode="stateHidden" to be like this

  <activity
      android:name="com.me.MyActivity"
      android:windowSoftInputMode="stateHidden"
   />

Upvotes: 2

Abhi
Abhi

Reputation: 9005

In the onResume() of Activity B hide the keyboard

public void onResume()
{
  super.onResume();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

In the onPause() of Activity A hide the keyboard

public void onPause()
    {
      super.onPause();
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }

Upvotes: 9

Related Questions