3

I have an iPhone app that uses different keyboard layouts. Some are custom and some are built in:

Numbers only:

Numbers only

Decimals:

Decimals

Custom X button for ISBN numbers:

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.

Android

How can I customize the keyboards in Android??

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
  • see this post maybe helpful for u http://stackoverflow.com/questions/8000795/android-keyboared-overlaps-with-the-edittext-with-printscreens – ρяσѕρєя K Dec 07 '12 at 22:21

5 Answers5

4

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.

Community
  • 1
  • 1
Gautam
  • 4,006
  • 3
  • 32
  • 37
3

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.

twaddington
  • 11,607
  • 5
  • 35
  • 46
0

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. :)

Aleksander Blomskøld
  • 18,374
  • 9
  • 76
  • 82
Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38
0

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.

Pier Betos
  • 1,038
  • 9
  • 17
0

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"
TopherC
  • 79
  • 3