强制对话框输入需要横向全屏 ime 软键盘
我有一个带有输入的对话框,我必须自动弹出软键盘,当前代码:
final EditText input = new EditText(this);
final AlertDialog dialog = new AlertDialog.Builder(ScActivity.this)
.setMessage(message)
.setView(input).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
// do positive stuff
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
}
}).create();
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}
});
dialog.show();
input.requestFocus();
这工作正常,除了一种行为。我第一次以横向模式显示此窗口时,对话框会向上跳,好像它试图为软键盘腾出空间,然后意识到没有足够的空间,向下跳,然后显示全屏 ime 键盘(与文本输入)。
看起来像是一个小故障。不想忍受它。尝试过以不同的顺序做事,按计时器做事。第一次之后,每次连续,键盘都会显示在顶部,没有跳跃。有人知道任何解决方法吗?我只想在横向模式下全屏显示软键盘(纵向模式有足够的空间让对话框向上移动并可见。
谢谢
I have a dialog box with an input, I have to automatically pop up the soft keyboard, current code:
final EditText input = new EditText(this);
final AlertDialog dialog = new AlertDialog.Builder(ScActivity.this)
.setMessage(message)
.setView(input).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
// do positive stuff
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
}
}).create();
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
}
});
dialog.show();
input.requestFocus();
This works fine, except for one behavior. The first time I show this window in landscape the mode, the dialog box jumps up, as if it's trying to make room for the soft keyboard, then realizes there isn't enough room, jumps back down, then the fullscreen ime keyboard shows (with the text input).
It looks like a glitch. Don't want to live with it. Have tried doing things in different order, doing things on timers. Every consecutive time after the first, the keyboard shows up on top, no jumping. Anyone know of any workaround? I just want the soft keyboard to show up on top, fullscreen, in landscape mode (portrait mode has enough room for the dialog box to move up and be visible.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论