[英]Force show soft keyboard from within an AlertDialog
我有以下代碼,我認為應該在顯示警報對話框時強制顯示鍵盤。
public void showTypeBox(){
edit = new EditText(this);
edit.setPadding(10, 0, 0, 10);
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("Type word to search for:")
.setPositiveButton("Search", Main.this)
.setNegativeButton("Cancel", null)
.setView(edit)
.setIcon(R.drawable.menu_icon)
.create();
dialog.show();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT);
}
我看不出我在這里做錯了什么。
您試圖在EditText
布局和可見之前顯示鍵盤。 嘗試這個:
Handler delayedRun = new Handler();
delayedRun.post(new Runnable() {
@Override
public void run() {
edit.requestFocus();
InputMethodManager mgr = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(addressBox, InputMethodManager.SHOW_IMPLICIT);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.