仅在电话的 AlertDialog 中不显示软键盘 [英] Softkeyboard not showing in AlertDialog for phone only

本文介绍了仅在电话的 AlertDialog 中不显示软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么软键盘只在平板电脑上显示是个谜!

Why the softkeyboard is showing only on the tablet is a mystery !

这是我使用过的代码.

AlertDialog.Builder builder = new AlertDialog.Builder(CurrentActivityName.this);
builder.setTitle("Title");
builder.setMessage("Message");
final EditText input = new EditText(CurrentActivityName.this);
builder.setView(input);
builder.setPositiveButton(R.string.allow, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//my code
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//my code
}
});
builder.create().show();

我可以通过以下方式解决它使用 postDelayed毫秒数来发布可运行

I am able to solve it by using postDelayed with a number of milliseconds to post a Runnable

 input.requestFocus();
 input.postDelayed(new Runnable() {
 @Override
 public void run() {
 InputMethodManager keyboard = (InputMethodManager)
                        getSystemService(Context.INPUT_METHOD_SERVICE);
 keyboard.showSoftInput(input, 0);
                    }
                },200);

绝不推荐

硬编码延迟,因为它们可能会在不同条件/不同设备下引入不可预测的行为.

Hard-coded delays are never recommended because they may introduce unpredictable behavior under different conditions / different devices.

我正在寻找一些稳定的解决方案.

I am looking for some stable solution.

推荐答案

我解决了问题

AlertDialog alertDlg = builder.create();

alertDlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

alertDlg.show();

这篇关于仅在电话的 AlertDialog 中不显示软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆