只显示Android软键盘上的数字按钮?

Ben*_*erg 35 android android-softkeyboard

在Android的软键盘上,您可以设置软键盘以显示数字而不是使用az键盘android:inputType="numberDecimal".但是,如果我只想显示顶部数字行1 2 3 4 5 6 7 8 9 0而不是以下行开头,我该怎么办@ # $ % ...

Thanx听!

sof*_*arn 63

android:inputType="phone"
android:digits="1234567890"
Run Code Online (Sandbox Code Playgroud)

是一个选择

  • 我更喜欢你的解决方案而不是公认的方案 +1 (4认同)

小智 40

您只能在代码中添加以下行:

input.setRawInputType(Configuration.KEYBOARD_12KEY);
Run Code Online (Sandbox Code Playgroud)

这将显示数字键盘.


Jus*_*tin 10

电话号码垫是我找到的最接近的东西(设置inputType="phone"在你的身上EditText).


小智 8

接受的答案对我不起作用(在 OnePlus 3t 和三星 Galaxy S6/S7 手机上测试)。

此解决方案使用 numberPassword 但覆盖 EditText 的默认转换方法以显示字符而不是显示点。

<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());
Run Code Online (Sandbox Code Playgroud)