2

This works in a vast phone model list except for the Samsung A50:

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

enter image description here enter image description here

This is the "hotfix" work around:

<EditText
    ...
    android:digits="0123456789-"
    android:inputType="phone" />

Any idea, other than it's a Samsung, of the reason on why this is failing?

GuilhE
  • 11,591
  • 16
  • 75
  • 116

2 Answers2

2

You can achieve this in a more exact way using below:

android:digits="0123456789-"
android:inputType="numberSigned"

Output from A50S:

Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46
1

Different manufacturers do different things and some of them take the rules on how the GUI should display as mere suggestions (I have seen similar issues happen on a few Huawei devices in particular)

I would suggest checking your input with a regular expression after the user has entered it to see if the input has unexpected characters and if so reject it, as you can't guarantee that every mobile device's input display will show the way you've asked it to (even though that is kind of the point of using inputType and digits!)

tkingston
  • 114
  • 6
  • Yup, I'm also checking if the input is correct, but for a better UX the keyboard should be also limited to the type of input. In this case I want numeric with the possibility of an extra char `"-"`. – GuilhE Dec 04 '19 at 16:07