How do I show the number keyboard on an EditText i

2019-01-08 07:36发布

I just basically want to switch to the number pad mode as soon a certain EditText has the focus.

13条回答
不美不萌又怎样
2楼-- · 2019-01-08 07:47

You can configure an inputType for your EditText:

<EditText android:inputType="number" ... />
查看更多
时光不老,我们不散
3楼-- · 2019-01-08 07:47

To do it in a Java file:

EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-08 07:48

Define this in your xml code

android:inputType="number"
查看更多
倾城 Initia
5楼-- · 2019-01-08 07:49
EditText number1 = (EditText) layout.findViewById(R.id.edittext); 
    number1.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_CLASS_PHONE);
     number1.setKeyListener(DigitsKeyListener.getInstance("0123456789”));

This code will only takes numbers from "0123456789”, even if you accidentally type other than "0123456789”, edit text will not accept.

查看更多
Root(大扎)
6楼-- · 2019-01-08 07:52
editText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
查看更多
叛逆
7楼-- · 2019-01-08 07:57
EditText number1 = (EditText) layout.findViewById(R.id.edittext); 
number1.setInputType(InputType.TYPE_CLASS_NUMBER);
查看更多
登录 后发表回答