Only show number buttons on Soft Keyboard in Andro

2019-01-08 21:41发布

On the soft keyboard in Android you can set the soft keyboard to show the numbers instead of a-z keyboard using android:inputType="numberDecimal". However, what do I do if I only want to show the top number row 1 2 3 4 5 6 7 8 9 0 and not the following rows starting with @ # $ % ...?

Thanx for listening!

8条回答
别忘想泡老子
2楼-- · 2019-01-08 21:52

You must only add this line on your code:

input.setRawInputType(Configuration.KEYBOARD_12KEY);

this will show only the numeric keyboard.

查看更多
再贱就再见
3楼-- · 2019-01-08 21:54

Last I looked into it, Android did not have any good options for that. I ended up having to write my own version of a soft keyboard-like user interface.

查看更多
狗以群分
4楼-- · 2019-01-08 21:57

The phone number pad is the closest thing I've found (set inputType="phone" on your EditText).

查看更多
女痞
5楼-- · 2019-01-08 22:00

The accepted answer did not work for me (tested on OnePlus 3t and Samsung Galaxy S6/S7 phones).

This solution uses numberPassword but overrides the default transformation method for the EditText to show characters instead of showing dots.

<EditText
    android:id="@+id/userid"
    android:inputType="numberPassword"
    android:maxLength="6"
/>

// Numeric 6 character user id
EditText input = findViewById(R.id.userid);

// Process input and show characters instead of dots
input.setTransformationMethod(SingleLineTransformationMethod.getInstance());
查看更多
Rolldiameter
6楼-- · 2019-01-08 22:01
android:inputType="phone"
android:digits="1234567890"

is an option

查看更多
Animai°情兽
7楼-- · 2019-01-08 22:04

Just posted an answer here but re-posting for simplicity:

Seems Android has added the functionality we were seeking. This is the xml I use for simple EditText numeric entry:

    android:inputType="numberPassword"
    android:digits="0123456789"
    android:singleLine="true"
    android:ems="4"
    android:textColor="@android:color/black"
    android:gravity="center"
查看更多
登录 后发表回答