Reputation: 11
The demand is to display the default number of the keyboard can enter a negative number like this:
But there is no way to set the default for this way.
If you set this keyboard, you can not enter a negative number, click the minus sign is not responding.
Pure numeric keypad, but can not enter a negative number
Is there any solution?
Upvotes: 0
Views: 3286
Reputation: 2899
You have to create your own control for NumericEntry like:
public class NumericTextBox : Entry
{
public NumericTextBox()
{
this.Keyboard = Keyboard.Numeric;
}
}
Then, in your Android project, create Custom Renderer:
[assembly: ExportRenderer(typeof(NumericTextBox), typeof(CustomNumericTextboxRenderer))]
namespace xxx.Droid.Renderers
{
public class CustomNumericTextboxRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
var native = Control as EditText;
native.InputType = Android.Text.InputTypes.ClassNumber | Android.Text.InputTypes.NumberFlagSigned | Android.Text.InputTypes.NumberFlagDecimal;
}
}
}
This has been tested and working for Droid devices. It allows to enter negative/positive values with decimal point. It properly forbirs entering wrong decimal value.
Upvotes: 3