Soft KeyBoard不会以横向方向显示

时间:2014-05-09 15:47:10

标签: java android landscape portrait nexus-5

在我的应用中,我有一个EditText对话框。我编写它的方式是,只要对话框出现,软键盘就会出现,编辑文本将获得焦点,editText中的所有现有文本都会被预先选中。用户可以开始输入。当我以纵向方向拿着手机时,一切正常。但是当我有横向电话时,同样的事情也行不通。我的片段中的部分代码粘贴在下面。

final EditText inputDeviceId = new EditText(getActivity());
inputDeviceId.setInputType(InputType.TYPE_CLASS_TEXT);
String savedDevId = getDeviceID();
inputDeviceId.setText(savedDevId);
inputDeviceId.setSelectAllOnFocus(true);

// some more code ... to create dialog , ok cancel buttons then,
final AlertDialog alertDialog = alertDialogBuilder.create();
inputDeviceId.setOnFocusChangeListener(new View.OnFocusChangeListener() {       
    if(hasFocus){   
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
});

alertDialog.show();

现在这一切都以纵向工作,不适用于风景。 在横向模式下,带有edittext的对话框显示出来,它具有焦点,现有文本被预选,但不显示键盘。用户必须单击editText才能显示键盘。为什么?我正在使用nexus-5进行测试。

0 个答案:

没有答案