How to stop Soft keyboard showing automatically when focus is changed (OnStart event)

Maybe this will help you:

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

Put this method in the onCreate() method of your activity when the activity is first created or called.


We can Hide the device Keybord by following ways which totally depends on the need of situation_

First Way_

EditText userId;
    /*
     * When you want that Keybord not shown untill user clicks on one of the EditText Field.
     */
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Second Way_ InputMethodManager

    /*
     * When you want to use service of 'InputMethodManager' to hide/show keyboard
     */
    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    inputManager.hideSoftInputFromWindow(userId.getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);

Third Way_

    /*
     * Touch event Listener
     * When you not want to open Device Keybord even when user clicks on concern EditText Field.
     */
    userId.setOnTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int inType = userId.getInputType(); // backup the input type
            userId.setInputType(InputType.TYPE_NULL); // disable soft input
            userId.onTouchEvent(event); // call native handler
            userId.setInputType(inType); // restore input type
            userId.setFocusable(true);
            return true; // consume touch even
        }
    });

Behalf of all of the above ways_ you can also define windowSoftInputMode in applicationsmanifest` file_

<manifest ... >
 <application ... >
    <activity 
        android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
        ... >
        <intent-filter>
           ...
        </intent-filter>
    </activity>

 </application>
</manifest>

I hope this will help all!


If you want this for a particular EditText this will work.

editText.setShowSoftInputOnFocus(false);