Friday, August 7, 2015

Hide Keyboard in Android

Hide keyboard in android on button click or layout click some time we notice that after enter data in edittext when click button then still show keyboard on eittext, we need to hide keyboard on button click.

some time we switch one activity to another activity then if keyboard open in first activity then it also show in second activity.

hide soft keyboard in android
Hide keyboard android

Hide Soft Keyboard in Android: 

try { 
 InputMethodManager inputMethodManager = (InputMethodManager)                                                  this.getSystemService(Activity.INPUT_METHOD_SERVICE);inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
} catch (NullPointerException e) 
{
e.printStackTrace();
} catch (Exception e)
 {
e.printStackTrace();
}

On Start Activity Hide Keyboard in Android:


Some time on startup EditText  focus and Keyboard should be visible then hide it 

   <activity android:name="com.database.DataListActivity"
   android:windowSoftInputMode="stateHidden"  ></activity>

above code write in Manifest file where we define Activity.


Note: If any Issue during Implement this task then Please Comment.

Thank You 

No comments :

Post a Comment