How to hide Soft Keyboard when activity starts ?

In the AndroidManifest.xml

<activity android:name="com.your.package.ActivityName"
      android:windowSoftInputMode="stateHidden"  />


Also you can use the following functions to show/hide the keyboard


/**
 * Hides the soft keyboard
 */
public void hideSoftKeyboard()
{
    if(getCurrentFocus()!=null)
    {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

/**
 * Shows the soft keyboard
 */
public void showSoftKeyboard(View view)
{
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    view.requestFocus();
    inputMethodManager.showSoftInput(view, 0);
}

Comments

Popular posts from this blog

Android - Set cursor drawable programmatically

Create custom button in android

Android - Shared Preferences Tutorial