4

I've got an Entry control on my Xamarin application home page, which is used for entering a person's age. I've set the keyboard to be Keyboard="Numberic"

However, this is causing confusion as, for Android at least, the "Done" key is below backspace, but above the settings key as well as the .- key. This means when the user is trying to press "Done", they're forgetting that the key isn't in the bottom right-hand corner as you'd expect, and they keep pressing the settings key by mistake and going into their phone settings, which is a bit irritating, understandably.

Is it possible to either disable the settings key and the .- key, or swap their positions around? I'm not expecting it to be possible, so in which case, is there another way that I can get around this?

Screenshot to clarify what I mean - can the keys with the settings cog and the ".-" be moved or disabled, to prevent the user opening their phone settings and putting negative/decimal numbers in?

enter image description here

Diego Rafael Souza
  • 5,241
  • 3
  • 23
  • 62
David
  • 2,298
  • 6
  • 22
  • 56
  • You can always disable or strip characters out of the EditText field where the values of the buttons are placed. As far as disabling the settings or changing the order of buttons around, I am not so sure that can be done with the system keyboard, perhaps you need a custom keyboard for that type of functionality – ViaTech Jun 13 '18 at 11:46
  • @ViaTech are you able to give an example of the character disabling/stripping? It's my first Xamarin project so I'm still getting to grips with it. – David Jun 13 '18 at 11:48
  • 1
    Hmm...Xamarin, C#...give me a second I will need to do a little research – ViaTech Jun 13 '18 at 15:01
  • 1
    The android's keyboard is managed by the OS, each device can have different keyboards appearance and behavior. What if you try [something like proposed here and **create your own keyboard** app pattern](https://stackoverflow.com/questions/47787385/custom-keyboard-in-xamarin-forms)? – Diego Rafael Souza Jun 13 '18 at 19:12
  • 1
    Hey one note... I tried to edit this post to include C# in the tags, bit I accidentally wrote "C++" so I am sure it will be rejected. Please add C# to the tags so I don't have to change a rejected suggestion (as it should be rejected because xamarin uses c#). I feel adding this tag will improve suggestions and searchability... I was thinking Java when I first read everything over as that is the base for Android so I feel clarification via tags is best for this question – ViaTech Jun 14 '18 at 00:09

1 Answers1

0

I have not used C# in a bit and never with Android but the idea of removing characters from a String is most languages is normally simple enough.

Based on our small discussion in the comments, and a little research; I believe this is what you are looking for to strip unwanted values from the EditText field where the user's input goes in your application:

var editText = FindViewById<EditText> (Resource.Id.editText);

editText.TextChanged += (object sender, Android.Text.TextChangedEventArgs et) => {
    //step 1 grab editText value
    String newString = et.Text.ToString(); 

    //step 2 replace unwanted characters (currently '.' & '-')
    newString = newString.Replace(".", "").Replace("-", "");

    //step 3 set the editText field to the updated string
    editText.Text = newString;

};

Resource: https://github.com/xamarin/recipes/tree/master/Recipes/android/controls/edittext/capture_user_input_text

I have not found a way to change the default keyboard for Android so you can remove unwanted keys (i.e. the settings key) or reorder them, so I am still thinking if you decide that you must do this, you would need to build a custom keyboard for the application.

ViaTech
  • 2,143
  • 1
  • 16
  • 51