为什么软键盘仅在平板电脑上显示是一个谜!
这是我使用的代码。
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
与毫秒数来发布可运行
input.requestFocus();
input.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager keyboard = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(input, 0);
}
},200);
绝对不建议使用硬编码的延迟,因为它们可能会在不同的条件/不同的设备下引入不可预测的行为。
我正在寻找一些稳定的解决方案。
我解决了问题
AlertDialog alertDlg = builder.create();
alertDlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDlg.show();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句