Display Requirement-Specific Keyboard Using XAMARIN.FORMS

Xamarin uses the Keyboard class to show various virtual keyboards depending upon the user request. It contains several static properties to create various kinds of virtual keyboards. Xamarin displays the Default Keyboard, if nothing is specified.

Keyboard for Chatting

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Chat  
  10.          }  
  11.       }  
  12.    }  
  13. };  



It opens up the default virtual keyboard in the device that would be convenient for chatting, having a few extra keys.

Keyboard for Email entry

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Email  
  10.          }  
  11.       }  
  12.    }  
  13. };  
It opens up the same text virtual keyboard with some additional options for Email.

Keyboard for Numeric input

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Numeric  
  10.          }  
  11.       }  
  12.    }  
  13. };  



It opens the numeric virtual keyboard in the device. It assists in entering numbers and decimals in the entry field.

Keyboard for Telephone number input

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Telephone  
  10.          }  
  11.       }  
  12.    }  
  13. };  

This opens up the numeric virtual keyboard in the device with some additional keys like +, *, #, – and so on to help the user to enter a telephone number.

Keyboard for Text input

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Text  
  10.          }  
  11.       }  
  12.    }  
  13. };  

It opens a very similar keyboard as the Default one.

Keyboard for URL input

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Url  
  10.          }  
  11.       }  
  12.    }  
  13. };  

The keyboard opened by this method is the same as the Email one.

Keyboard to make the first letter of the sentence capitalized

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Create(KeyboardFlags.CapitalizeSentence)  
  10.          }  
  11.       }  
  12.    }  
  13. };  

It opens the same Default keyboard but makes the first letter of the sentence capitalized automaticly.

Keyboard for spell checking

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Create(KeyboardFlags.Spellcheck)  
  10.          }  
  11.       }  
  12.    }  
  13. };  

It opens the same Default keyboard but checks the spelling during typing.

Keyboard to auto suggest the word

  1. MainPage = new ContentPage()  
  2. {  
  3.    Content = new StackLayout()  
  4.    {  
  5.       Children =  
  6.       {  
  7.          new Entry()  
  8.          {  
  9.             Keyboard = Keyboard.Create(KeyboardFlags.Suggestions)  
  10.          }  
  11.       }  
  12.    }  
  13. };  

It opens the same Default keyboard but suggests the words to the user during typing.

Happy coding.


Similar Articles