Reference:
http://stackoverflow.com/questions/12997273/alertdialog-with-edittext-open-soft-keyboard-automatically-with-focus-on-editteUpdated 2016/1/15:
http://stackoverflow.com/questions/8785023/how-to-close-android-soft-keyboard-programatically
Code snippet:
Builder builder = new Builder(this);final EditText input = new EditText(this);
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
builder.setTitle(R.string.dialog_title_addsubject)
.setMessage(R.string.dialog_addsubject)
.setView(input)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
.......
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
/* updated 2016/1/15
* to hide it, call the method again
* imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
*/
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
/* updated 2016/1/15
* to hide it, call the method again
* imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
*/
}
});
builder.show();
input.requestFocus();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
沒有留言:
張貼留言