Jay
Jay

Reputation: 49

Xamarin.Forms: Custom keyboard uses dot (.) instead of comma (,) for a german app. How to change that?

I had to use a custom entry to open a keyboard that even includes a decimal place with an numeric input type:

 protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);


            GradientDrawable gd = new GradientDrawable();
            gd.SetColor(global::Android.Graphics.Color.Transparent);
            this.Control.SetBackgroundDrawable(gd);
            this.Control.SetRawInputType(InputTypes.TextFlagNoSuggestions);
            Control.SetHintTextColor(ColorStateList.ValueOf(global::Android.Graphics.Color.Rgb(169, 169, 169))) ;


            if (Control != null)
            {
                this.Control.KeyListener = DigitsKeyListener.GetInstance(true, true); // I know this is deprecated, but haven't had time to test the code without this line, I assume it will work without
                this.Control.InputType = Android.Text.InputTypes.ClassNumber | Android.Text.InputTypes.NumberFlagDecimal;
            }

            if (Control == null || e.NewElement == null) return;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                Control.BackgroundTintList = ColorStateList.ValueOf(Android.Graphics.Color.Rgb(194, 213, 231));
            else
                Control.Background.SetColorFilter(Android.Graphics.Color.Rgb(194, 213, 231), PorterDuff.Mode.SrcAtop);
        }

However, this only gives me a dot as a decimal place, but the app itself is german. So i need to display a comma instead of a dot. But the comma is greyed out.

How do I get ther?

Upvotes: 2

Views: 675

Answers (1)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10958

You could set the Keyboard property in xaml instead of custom renderer.

  <local:MyEntry Keyboard="Numeric" Placeholder="Entry" />

enter image description here

Upvotes: 1

Related Questions