Nick Goloborodko
Nick Goloborodko

Reputation: 3053

Xamarin Forms Numeric Keyboard - enable space and dash buttons

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

Upvotes: 3

Views: 1984

Answers (1)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10968

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)

Upvotes: 4

Related Questions