Android text and input-create input method (4)

Source: Internet
Author: User

Intercepts hardware key events

Even if the input method window does not have a clear focus, it first receives the hardware key events and can choose whether to use or forward them to the application. For example, during text orchestration, you can use the arrow keys to navigate in the candidate area of the input UI. You can also capture the rollback key to eliminate any window popped up from the input method window.

Override the onkeydown () and onkeyup () methods to obtain the hardware key events.

Remember to call the super () method for buttons that do not want to be processed by yourself.

Create an IME subtype

Run IME as a child to display multiple input modes and languages supported by IME. A sub-type can be expressed:

1. A language environment, such as en_us or fr_fr;

2. An input mode, such as voice, keyboard, or handwriting;

3. Other input styles, formats, or special IME attributes, such as 10 keys or QWERTY keyboard la S.

Basically, the mode is any text, such as "keyboard" and "voice.

A child type can also be a combination of these types.

Subtype information is used for Input Method switching. It can be used in the notification bar and in the ime settings window. This information also allows the framework to directly carry a specific IME subtype. When creating an IME, you can easily use the child type because it helps the user identify and switch between different IME languages and modes.

Use the <subtype> element to define a seed type in the XML resource file of the input method. The following example defines two seed types: one is the keyboard subtype used in the American English environment, and the other is the keyboard subtype used in the French Environment:

<Input-method xmlns: Android = "http://schemas.android.com/apk/res/android"


Android: settingsactivity = "com. example. softkeyboard. Settings"


Android: icon = "@ drawable/ime_icon"


<Subtype Android: Name = "@ string/display_name_english_keyboard_ime"


Android: icon = "@ drawable/subtype_icon_english_keyboard_ime"


Android: imesubtypelanguage = "en_us"


Android: imesubtypemode = "keyboard"


Android: imesubtypeextravalue = "someprivateoption = true"


/>


<Subtype Android: Name = "@ string/display_name_french_keyboard_ime"


Android: icon = "@ drawable/subtype_icon_french_keyboard_ime"


Android: imesubtypelanguage = "fr_fr"


Android: imesubtypemode = "keyboard"


Android: imesubtypeextravalue = "foobar = 30, someinternaloption = false"


/>


<Subtype Android: Name = "@ string/display_name_german_keyboard_ime"


...


/>

/>

Use % s to obtain the same child type label as the child type language label to ensure that your child type is correctly marked in the UI. Some XML files of the input method are as follows:


<Subtype


Android: Label = "@ string/label_subtype_generic"


Android: imesubtypelocale = "en_us"


Android: icon = "@ drawable/icon_en_us"


Android: imesubtypemode = "keyboard"/>

Below are some of the ime strings. XML files. The string resource label_subtype_generic is used by the UI of the input method to set sub-type labels. The definition is as follows:

<Stringname = "label_subtype_generic"> % S </string>

In this way, the subtype display name is set to "English (United States)" In any English language environment, or other corresponding languages.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.