edisonthk
edisonthk

Reputation: 1423

Prevent softkeyboard appear from other activity

I got a EditText on my first tab. Of course, soft keyboard appearing when I touch on my EditText. But when I access to second tab, it means second tab activity, soft keyboard stay appearing on my first tab and don't disappear even though there is no EditText on my second tab activity.

I want to prevent softkeyboard from appearing when I access to my second tab.

How can I solve this problems?

Here's my manifest files

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidaccountbook"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name="com.example.androidaccountbook.AccountTabActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
             <!--  screenOrientation prevent from rotation -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity android:name="com.example.androidaccountbook.accountMainThread"
             android:windowSoftInputMode="stateHidden" />

        <!-- activity for intent -->
        <activity android:name="com.example.androidaccountbook.TodayExpenseList"
            android:windowSoftInputMode="stateHidden" />        
        <activity android:name="com.example.androidaccountbook.settingThread" 
            android:windowSoftInputMode="stateHidden"/>
        <activity android:name="com.example.androidaccountbook.FailedConnectDatabase" 
            android:windowSoftInputMode="stateHidden"/>

    </application>

    <uses-permission android:name="android.permission.INTERNET"/>

</manifest>

Upvotes: 1

Views: 909

Answers (3)

edisonthk
edisonthk

Reputation: 1423

I figured how to works on it and I tried it, it works.

Because I want to access to second activity, and surely life-activity onPause method will occurs. So, I wrote the following hideKeyboard method on my onPause method.

This is how onPause method looks like

@Override
protected void onPause(){
    super.onPause();

    hideKeyboard(this,editText);

}

This is my hideKeyboard method looks like

public void hideKeyboard(Context context, EditText text){
        InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(text.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
    }

Upvotes: 1

shym
shym

Reputation: 299

I use this and it always works:

<activity
        android:name="MyProfileActivity"
        android:windowSoftInputMode="stateHidden|adjustPan" />

Upvotes: 0

Junaid
Junaid

Reputation: 7860

The best solution would be: (In the Manifest file)

<activity android:name=".MainActivity" 

    android:windowSoftInputMode="stateHidden" />

Upvotes: 0

Related Questions