![](/img/trans.png)
[英]EditText inside a alertDialogue is not showing softkeyboard in Android
[英]Showing softkeyboard on change in focus edittext android
当焦点改变时,我正在使用下面的代码显示编辑框的键盘。
no1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
if(keyCode == 66) {
no2.requestFocus();
}
}
return false;
}
});
no2.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
if(keyCode == 66) {
//Log.e("I am inside no2","no2");
no3.requestFocus();
return true;
}
}
return false;
}
});
no2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
Log.e("In","Innnnnn");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(no2, InputMethodManager.SHOW_IMPLICIT);
}
}
});
但是,键盘不显示。 正在打印日志语句。 因此,这意味着它正在进入focusChanged方法。 有什么想法我做错了吗?
使用InputMethodManager控制键盘。
尝试这个...
final AlertDialog dialog = ...;
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
尝试这个
InputMethodManager inputMethodManager=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.