I am developing for a tablet using Android 2.2.
I have a form which I am using for new and editable instances. When editable, I want to stop the user from editing c
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 applications
manifest` 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);
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.
this is the answer: In your AndroidManifest.xml add an attribute to the Activity:
<activity android:name=".MyActivity" android:windowSoftInputMode="adjustPan"> </activity>