Working with Textual Input Methods Android

The Android SDK includes input method framework classes that enable interested developers to use powerful input methods as well as create their own input methods, such as custom software keyboards and other Input Method Editors (IMEs). Users can download custom IMEs to use on their devices. For example, there’s nothing stopping a developer from creating a custom keyboard with Lord of the Rings-style Elvish characters, smiley faces, or Greek symbols.

Working with Software Keyboards

Because text input methods are locale-based (different countries use different alphabets and keyboards) and situational (numeric vs. alphabetic vs. special keys), the Android platform has trended toward software keyboards as opposed to relying on hardware manufacturers to deliver specialized hardware keyboards.

Choosing the Appropriate Software Keyboard

The Android platform has a number of software keyboards available for use. One of the easiest ways to enable your users to enter data efficiently is to specify the type of input expected in each text input field.

For example, to specify an EditText that should take only capitalized textual input, you could set the inputType attribute as follows:

<EditText android:layout_height="wrap_content"

This shows a number of EditText controls with different inputType configurations.

EditText Controls with different input types.

EditText Controls with different input types.

The input type dictates which software keyboard is used by default and it enforces appropriate rules, such as limiting input to certain characters. Figure (left) illustrates what the software keyboard looks like for an EditText control with its inputType attribute set to all capitalized text input. Note how the software keyboard keys are all capitalized. If you were to set the inputType to textCapWords instead, the keyboard switches to lowercase after the first letter of each word and then back to uppercase after a space. Figure (middle) illustrates what the software keyboard looks like for an EditText control with its inputType attribute set to number. Figure (right) illustrates what the software keyboard looks like for an EditText control with its inputType attribute set to textual input, where each sentence begins with a capital letter and the text can be multiple lines.

The software keyboards associated with specific input types.

The software keyboards associated with specific input types.

Depending on the user’s keyboard settings (specifically, if the user has enabled the Show Suggestions and Auto-complete options in the Android Keyboard settings of his device), the user might also see suggested words or spelling fixes while typing.

For a complete list of inputType attribute values and their uses, see http://developer.

For more fine-tuned control over input methods, see the android. view. inputmethod. InputMethod Manager class.

Providing Custom Software Keyboards

If you are interested in developing your own software keyboards, we highly recommend the following references:

  • IMEs are implemented as an Android service. Begin by reviewing the Android packages called android.inputmethodservice and android.view.inputmethod, which can be used to implement custom input methods.
  • The SoftKeyboard sample application in the Android SDK provides an implementation of a software keyboard.
  • The Android Developer technical articles on onscreen input methods and creating an input method .

Working with Text Prediction and User Dictionaries

Text prediction is a powerful and flexible feature available on Android devices. We’ve already talked about many of these technologies in other parts of this book, but they merit mentioning in this context as well.

  • In Chapter “Exploring User Interface Screen Elements,” you learned how to use AutoCompleteTextView and MultiAutoCompleteTextView controls to help users input common words and strings.
  • In Chapter “Using Android Data and Storage APIs,” you learned how to tie an AutoCompleteTextView control to an underlying SQLite database table.
  • In Chapter “Sharing Data Between Applications with Content Providers,” you learned about the UserDictionary content provider (android.provider.UserDictionary), which can be used to add words for the user’s custom dictionary of commonly used words.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Android Topics