Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juniorcesarabreu/4324e43b6046f5ddcde80389c66eb90f to your computer and use it in GitHub Desktop.
Save juniorcesarabreu/4324e43b6046f5ddcde80389c66eb90f to your computer and use it in GitHub Desktop.
Soft keyboard with comma instead of dot for decimal separator in android

You can use the following workaround to also include comma as a valid input:-

Through XML:

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

Programmatically:

EditText input = new EditText(THE_CONTEXT);
input.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));

In this way Android system will show the numbers' keyboard and allow the input of comma. Hope it helps :)

Font: https://stackoverflow.com/a/16772680/7482458

@juniorcesarabreu
Copy link
Author

Not tested

A variation on the 'digit' solutions offered here:

char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
input.setKeyListener(DigitsKeyListener.getInstance("0123456789" + separator));

Taking into account the locale separator.

Font: https://stackoverflow.com/a/34256139/7482458

@AnthonyNahas
Copy link

thank for sharing :+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment