我使用InputMethodManager在需要时以编程方式显示软键盘
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);是否存在强制键盘显示为数字或电话键盘?
编辑
对不起,在我不得不离开电脑一段时间之前,我匆忙地打了这个字。我忘了提到可能是最关键的部分。我正试着在网页上做这个。我关注的文本框的输入类型设置为tel。由于某些原因,numpad不会出现在自动对焦上,这就是为什么我试图用InputMethodManager强制它。我当前的方法显示键盘,重点放在正确的字段上,只是看上去没有正确地读取类型和显示。
谢谢你到目前为止的所有回答(这确实回答了我措辞不佳的问题)。
发布于 2014-07-28 05:49:01
以下代码将向您显示键盘:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);但是,如果您想要强制显示为数字或电话键盘的键盘,则必须在该特定视图/小部件上设置输入类型。
InputType.TYPE_CLASS_NUMBER;
InputType.TYPE_CLASS_PHONE;例如:
your_edit_text.setInputType(InputType.TYPE_CLASS_NUMBER);发布于 2014-07-28 05:37:23
对数字使用此代码:
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:inputType="number"
android:padding="10dp"
android:singleLine="true" />&使用此代码用于电话:
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:inputType="phone"
android:padding="10dp"
android:singleLine="true" />要以编程方式尝试以下操作
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);密码是编辑文本的地方。
这会管用的。
发布于 2014-07-28 05:39:17
( a)在xml中
android:inputType="number"( b)编码
EditText editView = new EditText(this);
editView.setKeyListener(new DigitsKeyListener());https://stackoverflow.com/questions/24988897
复制相似问题