问题
I have an iPhone app that uses different keyboard layouts. Some are custom and some are built in:
Numbers only:
Decimals:
Custom X button for ISBN numbers:
I'd like to do the same thing on Android, but even the normal InputType.TYPE_CLASS_NUMBER
still includes a decimals, space, comma, etc.
How can I customize the keyboards in Android??
回答1:
It's not possible using the built-in keyboard. You'll have to develop a custom soft keyboard, or write an inline view that works like a keyboard replacement.
回答2:
I think this question has already been answered on StackOverflow. Look at this:
Only show number buttons on Soft Keyboard in Android?
@twaddington is correct that what you are asking for won't be possible with the built-in keyboard. One thing you can do to prevent non-digits from being entered is set the following in XML for your EditText
.
android:inputType="phone"
android:digits="1234567890"
If you want to this in code, and not in XML, I think this should work:
numericField.setInputType(Configuration.KEYBOARD_12KEY);
numericField.setKeyListener(new DigitsKeyListener());
To develop your own numeric soft keyboard, this tutorial may help.
回答3:
Please use inputType = "number", then you will get only number keypad.
<EditText android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
I hope it will help you. :)
回答4:
There is a way. Use
numericField.setInputType(InputType.TYPE_NUMBER_VARIATION_NORMAL|InputType.TYPE_CLASS_NUMBER);
It anticipates number pad only on Holo, and backward compatible number pad on lower versions.
回答5:
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"
来源:https://stackoverflow.com/questions/13771865/is-there-a-way-to-get-an-android-soft-keyboard-that-has-only-numbers-no-decimal