【问题标题】:Force Keyboard visible in alert dialog box强制键盘在警报对话框中可见
【发布时间】:2012-09-28 09:17:34
【问题描述】:

我想使用一个警告对话框,其中有几个编辑文本,以便用户可以键入然后单击保存按钮。

我已经使用我的布局xml(名为custom_dialog_add的xml)成功地扩充了我的alertdialog,代码如下:

   public OnClickListener saveButtonListener = new OnClickListener()
   // create a new Button and add it to the ScrollView   
   {
      @Override
      public void onClick(View v) 
      {   

          AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setView(getLayoutInflater().inflate(R.layout.custom_dialog_add, null));
            builder.create();

            View view = getLayoutInflater().inflate(R.layout.custom_dialog_add, null); 

            builder.setPositiveButton(R.string.OK, null);             
            AlertDialog Custom_dialog_add = builder.create();
            Custom_dialog_add.show();

警报对话框中的 EditText 和 Button 名称为 A_EditText、B_EditText 和 Button_Save。

如何在警报对话框内强制键盘打开/始终可见,无论 EditTexts 是否聚焦?

非常感谢!!

【问题讨论】:

    标签: android keyboard android-alertdialog


    【解决方案1】:

    试试这个:

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(YOUREDITTEXTHERE, InputMethodManager.SHOW_IMPLICIT);
    

    将 YOUREDITTEXTHERE 替换为您的 EditText 视图

    【讨论】:

      【解决方案2】:

      在显示对话框后,您应该能够在EditTexts 之一上requestFocus(),这应该会调出键盘。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-22
        • 1970-01-01
        • 1970-01-01
        • 2013-05-11
        • 2016-10-22
        • 1970-01-01
        • 2017-10-05
        相关资源
        最近更新 更多