我在 Android 应用程序编码中遇到了一个非常简单的问题。我有一个 EditText
对象列表,每行一个。
当用户长按 EditText
时,我需要显示键盘。当用户长按时,我调用这个方法:
private void setNameAsEditable(View rowView, boolean setToEditable) {
EditText textView = (EditText) rowView
.findViewById(R.id.edittext_name);
textView.setFocusableInTouchMode(setToEditable);
textView.setFocusable(setToEditable);
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
}
edittext 变为可编辑(出现下划线和光标,如下所示)
但是键盘没有出现。
我尝试了 stackoverflow 的各种解决方案(例如 this ),但都没有成功。
我什至尝试过
this.getWindow().setSoftInputMode ( WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
我希望软键盘在用户长按 EditText
时立即出现。有人可以帮忙吗?
最佳答案
尝试一下,对我来说效果很好。
et =(EditText) findViewById(R.id.edittext_name);
imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
et.setText("hide key board");
et.setFocusable(false);
et.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
et.setFocusableInTouchMode(true);
imm.showSoftInput(et, 0);
et.setText("show key board long pressed");
return false;
}
});
关于安卓 : show keyboard in edittext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20737686/