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条回答
SAY GOODBYE
2楼-- · 2019-01-08 07:58

If you need fractional number, then this is the answer for you:

android:inputType="numberDecimal"
查看更多
疯言疯语
3楼-- · 2019-01-08 07:59

You can do it 2 ways

  1. Runtime set

    EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    
  2. Using XML

    <EditText
        ...
        android:inputType="number" />
    
查看更多
仙女界的扛把子
4楼-- · 2019-01-08 08:02

I found this implementation useful, shows a better keyboard and limits input chars.

<EditText
    android:inputType="phone"
    android:digits="1234567890"
    ...
/>

Additionally, you could use android:maxLength to limit the max amount of numbers.

To do this programmatically:

editText.setInputType(InputType.TYPE_CLASS_PHONE);

KeyListener keyListener = DigitsKeyListener.getInstance("1234567890");
editText.setKeyListener(keyListener);
查看更多
做自己的国王
5楼-- · 2019-01-08 08:02
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ...
    android:inputType="number|phone"/> 

will show the large number pad as dialer.

查看更多
爷、活的狠高调
6楼-- · 2019-01-08 08:06

If you are using your EditText in Dialog or creating dynamically and You can't set it from xml then this example will help you in setting that type of key board while you are using dynamic Edit Text etc

myEditTxt.setInputType(InputType.TYPE_CLASS_NUMBER);

where myEditTxt is the dynamic EDIT TEXT object(name)

查看更多
淡お忘
7楼-- · 2019-01-08 08:06

Use the below code in java file

editText.setRawInputType(Configuration.KEYBOARD_QWERTY);

查看更多
登录 后发表回答