3

I have been reading some threads about this problem and some are not answered and others (from 2011) explain how this was a known bug.

Has this been solved? Is it possible right now to show soft keyboard with culture information? I would like to show a decimal keyboard showing a "," instead of a "dot" for the decimal separator.

Kromster
  • 7,181
  • 7
  • 63
  • 111
Notbad
  • 5,936
  • 12
  • 54
  • 100
  • My fix is here: [enter link description here](https://stackoverflow.com/a/63520135/11033601) – Alex K Aug 21 '20 at 09:31
  • 2
    [See here](https://developer.android.com/reference/android/text/method/DigitsKeyListener#getInstance(java.util.Locale,%20boolean,%20boolean) ) The DigitsKeyListener now accepts, locale which makes the softInput keyboard to accept ',' or '.' as decimal separator based on the locale. – Padmaja Seshadri Oct 02 '20 at 07:11

4 Answers4

17

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

MiaN KhaLiD
  • 1,478
  • 1
  • 16
  • 28
3

It is not possible to not show the '.' in the soft keyboard without creating your own one. The solution than I found is:

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

This way when you press the '.' in the soft keyboard nothing happens; only numbers and comma are allowed

2

I solved this by extending NumberKeyListener to accept ',' and '.', and overrode:

@Override
public int getInputType() {
   return InputType.TYPE_CLASS_NUMBER 
          | InputType.TYPE_NUMBER_FLAG_DECIMAL 
          | InputType.TYPE_NUMBER_FLAG_SIGNED;
}

Furthermore I set a TextWatcher on the EditText, which replaced all '.' with ',' in afterTextChanged().

But I could not manage to show a comma on the softkeyboard.

Bondax
  • 3,143
  • 28
  • 35
-4

In android namespace you can use:

android:inputType="numberDecimal"

Which enables you to input the "."

android
  • 43
  • 8