Reputation: 1093
I have an activity
which opens up a dialog
that contains edittexts
on a button
click. As soon as the dialog
opens the softkeyboard
shows. I want to prevent this. Only when I click on the edittext
in the dialog
should the softkeyboard
appear. I am using Android 4.
Thanks in advance
Upvotes: 1
Views: 596
Reputation: 1093
This should work is any case:
public void hideKeyboard() {
mActivity.runOnUiThread(new Runnable() {
public void run() {
InputMethodManager inputManager = (InputMethodManager) mActivity
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(mActivity
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
});
}
Upvotes: 0
Reputation: 1093
adding this to your Manifest is all you hav to do:
android:windowSoftInputMode="stateHidden"
Simple, but in case someone was looking here
:)
Upvotes: -1
Reputation: 1756
To achieve this, set the soft input mode just before you call dialog.Show():
// Build and create your dialog.
AlertDialog dialog = new AlertDialogBuilder(...).create();
// Hide soft keypad by default (will be displayed when user touches any edit field).
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
// Show the dialog.
dialog.show();
Upvotes: 3