Android-以编程方式使EditText不显示键盘 [英] Android - EditText made programmatically not showing keyboard
本文介绍了Android-以编程方式使EditText不显示键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 ArrayAdapter< String>
的情况下制作了一个应用程序,并以编程方式在相对布局中创建了editText视图,该布局均在 AppCompatDialogFragment
.每个editTexts都显示出来,我可以单击它们,但是如果没有打开键盘来输入.我尝试过类似的事情:
I am making an app where I am using a ArrayAdapter<String>
and I am programmatically making an editText view inside of a Relative Layout which is all inside of a AppCompatDialogFragment
. Each of the editTexts are showing up and I can click on them, but if it doesn't open the keyboard to type. I have tried things like:
EditText editText = (EditText) findViewById(R.id.myTextViewId);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
即使我尝试手动打开键盘,它也仍然无法打开.
Even if I try to manually open the keyboard, it still doesn't open.
RelativeLayout listLayout = new RelativeLayout(this.getContext());
listLayout.setLayoutParams(new AbsListView.LayoutParams(
AbsListView.LayoutParams.WRAP_CONTENT,
75));
if(super.getItem(position) == ParameterTypes.String.toString()) {
EditText editText = new EditText(this.getContext());
editText.setWidth(500);
editText.setHint(parameterNames[position]);
editText.setInputType(InputType.TYPE_CLASS_TEXT);
listLayout.addView(editText);
} else if(super.getItem(position) == ParameterTypes.Integer.toString()) {
EditText editText = new EditText(this.getContext());
editText.setWidth(500);
editText.setHint(parameterNames[position]);
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
listLayout.addView(editText);
} else if(super.getItem(position) == ParameterTypes.Double.toString()) {
EditText editText = new EditText(this.getContext());
editText.setWidth(500);
editText.setHint(parameterNames[position]);
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
listLayout.addView(editText);
return listLayout;
推荐答案
尝试一下
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
在xml
android:focusableInTouchMode="true"
这篇关于Android-以编程方式使EditText不显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文