3

I have a requirement where a field in a Xamarin Forms app is allowed to have only numbers, spaces and dashes. Numeric keyboard layout appears to be perfect for this purpose - the only trouble - the space and dash buttons do not appear to work? Is there any way to enable these, specifically on Android - as that is the primary target platform.

Buttons in question are highlighted.

<Entry
                            x:Name="BarcodeEntry"
                            Margin="12,0"
                            HeightRequest="40"
                            Placeholder="Barcode"
                            Style="{StaticResource BorderlessEntryStyle}"
                            Keyboard="Numeric"
                            Text="{Binding Barcode.Value, Mode=TwoWay}">

Control is bound to this property:

private string _barcode;
        public string Barcode
        {
            get => _barcode;
            set { SetProperty(ref _barcode, value); }

enter image description here

Nick Goloborodko
  • 2,883
  • 3
  • 21
  • 38

1 Answers1

4

For the numberic keyboard, we only have four related InputTypes.

  • number: A numeric only field.
  • numberDecimal: Can be combined with number and its other options to allow a decimal (fractional) number.
  • numberPassword: A numeric password field.
  • numberSigned: Can be combined with number and its other options to allow a signed number.

For more details about the InputTypes, you could refer to the link below. https://developer.android.com/reference/android/widget/TextView#attr_android:inputType

If you want to use the space and dash buttons, you could use the Telephone keyboard. Or you could create your own custom keyboard.

Custom Keyboard: Numeric keyboard as default on Xamarin.Forms, but allow text (cross platform)

Wendy Zang - MSFT
  • 10,509
  • 1
  • 7
  • 17
  • Thank you, looks like I'll have to go with TelephoneKeyboard for now, as I don't feel adventurous enough to create a custom keyboard just yet. – Nick Goloborodko Oct 21 '21 at 23:52