when using AlertDialog.Builder with EditText, the Soft Keyboard doesn't pop

前端 未结 12 1302
一生所求
一生所求 2020-11-30 23:13

I am using AlertDialog.Builder in order to create an input box, with EditText as the input method.

Unfortunately, the Soft Keyboard doesn\'t pop, al

12条回答
  •  [愿得一人]
    2020-11-30 23:48

    When you call showDialog() to show a Dialog created using AlertDialog in onCreateDialog()

    You should put the code in onPrepareDialog():

    @Override
    protected void onPrepareDialog (int id, Dialog dialog, Bundle args)
    {
        TextView editText=(TextView) dialog.findViewById(R....);
    
        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
           @Override
           public void onFocusChange(View v, boolean hasFocus) {
             if (hasFocus) {
                dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
             }
           }
        });
    }
    

提交回复
热议问题