Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Programatically close/hide Android Soft Keyboard on Events

    • 0
    • 3
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 210
    Comment on it

    When there are one or more EditText in the activity, a soft keyboard automatically appears when the activity is launched, which hides some visible portion of the screen and we don't always have a requirement to automatically pop-up the soft input keyboard. We can solve this by editing Manifest.xml file. Add the following attribute inside the particular Activity tag in Manifest.xml file -

    android:windowSoftInputMode="stateAlwaysHidden"
    

    It will keep the Keyboard hidden when the activity is resumed.

    or, in your Activity class call the following method -

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

    You can also close a keyboard on any event like on button click by using InputMethodManager class by calling hideSoftInputFromWindow and passing the desired parameters -

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

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: