InputMethodManager show numpad in webview

2019-07-20 14:28发布

I'm using the InputMethodManager to programmatically display the softkeyboard when it's needed

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);

Is there anyway to force the keyboard that appears into being the Number or telephone keypad?

Edit

Sorry I typed this in a hurry before I had to leave my computer for a while. I forgot to mention possibly the most crucial part. I'm trying to do this in a webview. The input type of the textbox i'm focusing on is set to tel. For some reason the numpad won't show up on autofocus which is why I'm trying to force it with InputMethodManager. My current method displays the keyboard focused on the correct field it just doesn't seem to read the type and display correctly.

Thanks for all of your answers so far(which did answer my poorly worded question).

3条回答
The star\"
2楼-- · 2019-07-20 14:43

a) in xml

android:inputType="number"

b) in code

EditText editView = new EditText(this);
editView.setKeyListener(new DigitsKeyListener());
查看更多
甜甜的少女心
3楼-- · 2019-07-20 14:59

Use this code for Number :

  <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" />

& use this code for Phone :

 <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" />

For Programmatically try this

password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);

Where password is edittext.

This will Work.

查看更多
Ridiculous、
4楼-- · 2019-07-20 15:01

Following code will display keypad to you:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);

However if you want to force the keyboard that appears into being the Number or telephone keypad, then you have to set the input type on that particular view/widget.

InputType.TYPE_CLASS_NUMBER; 
InputType.TYPE_CLASS_PHONE;

eg.

your_edit_text.setInputType(InputType.TYPE_CLASS_NUMBER);
查看更多
登录 后发表回答