2011-03-05 65 views
2

當顯示對話框EditText創建AlertDialog.Builder時是否可以自動顯示軟鍵盤?Android AlertDialog.Builder和softkeyboard

我已經看到了一些關於該主題的討論,但是我沒有找到任何可行的解決方案。

回答

1

解決了這個

InputMethodManager imm = (InputMethodManager) 
      SettingsActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE); 

    mDialog = mDialogBuilder.create(); 

    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 

     public void onDismiss(DialogInterface dialog) { 
      dismissSoftKeyboard(); 
     } 
    }); 

    mPinDialog.show(); 
    showSoftKeyboard(); 

} 

private void showSoftKeyboard() { 
    if (imm != null) { 
     imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
    } 
} 

private void dismissSoftKeyboard() { 
    if (imm != null) { 
     imm.toggleSoftInput(InputMethodManager.HIDE_NOT_ALWAYS, 0); 
    } 
} 
3

還有對皮膚有貓鼬的方法不止一種。

AlertDialog.Builder builder = new AlertDialog.Builder(CurrentActivityName.this); 
builder.setTitle(「Title」); 
builder.setMessage(「Message」); 

etc.. 

//This is the crucial part 
AlertDialog alertDlg = builder.create(); 
alertDlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 

alertDlg.show(); 

它工作在兩個手機和平板電腦好

Reference