How to hide Android Soft Keyboard

If you want to hide the Android Soft Keyboard, you can use following methods to do that.

Method 1

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Method 2


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

Method 3

Add following code into the AndroidManifest.xml file, inside the Activity tag.

android:windowSoftInputMode="stateHidden"

Method 4

Try below code inside onCreate() method in your activity class.


EditText edtView=(EditText)findViewById(R.id.editTextConvertValue);
edtView.setInputType(0);

or

editView.setInputType(InputType.TYPE_NULL);

***This method works as a means of getting around the "can't hide the soft keyboard" bug in 2.0 and 2.1 as described in code.google.com/p/android/issues/detail?id=7115

Method 5

If you work with TabHost and you want to hide the keyboard on onTabChanged() method, try the following code.


tabHost.setOnTabChangedListener(new OnTabChangeListener()
        {
        public void onTabChanged(String tabId)
            {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(tabHost.getApplicationWindowToken(), 0);
            }
        }


Method 6


 InputMethodManager inputManager = (InputMethodManager)      
  Context.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),    
    InputMethodManager.HIDE_NOT_ALWAYS);

or without Context Class calling,


InputMethodManager inputManager = (InputMethodManager)                        getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),    
    InputMethodManager.HIDE_NOT_ALWAYS);

Method 7


InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

Method 8


//Show soft-keyboard:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//hide keyboard :
 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Method 9


// Show soft-keyboard:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

// Hide soft-keyboard:
getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Some may not work for you, but some may work. Do experiment and let me know what works for you.






Comments

Popular posts from this blog

There was a problem saving your changes. Please try again later.

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'