N Kaushik

How to allow EditText to accept comma and numbers in Android

April 08, 2020

How to allow EditText to accept comma and numbers in Android

We have a lot of different input type attributes for Android EditText. Based on this type, they keyboard may show different keys. For example, if we mark it as number, the keyboard will show one keyboard with only numbers like below :

android edittext input

The , and . are appearing here with the keyboard, but you can’t click them as we are using number inputType attribute here.

How to allow comma with numbers :

If you want to allow , and numbers as inputs for the EditText, open it in xml mode and add the following in the EditText component :

<EditText
...
android:digits="0123456789,"
...
/>

That’s it. You will be able to inset comma with numbers.


Subscribe to my Newsletter