Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

android - Behaviour of imeOptions, imeActionId and imeActionLabel

I'm quite new to Android native development, and I'm trying to figure out how to customize the IME action buttons. I've looked at the Google documentation, but I can find very few information about the expected behaviour.

From the offical guide I understand that the keyboard action button can be configured using the attributes:

  • android:imeOptions can set the text/id of the button displayed near the space key to some pre-defined values (E.g. actionGo set the key label to Go and the id to 2)
  • android:imeActionLabel set the label of the button displayed inside the input area when the keyboard is fullscreen, usually in landscape mode. Can be set to any string value.
  • android:imeActionId same as previous but set the numeric Id passed to the callback method

But after some empiric attempts I've found different behaviour between API level 15 and next API levels.

I've set up a simple EditText element with the following attributes:

<EditText
        ...
        android:imeOptions="actionGo"
        android:imeActionLabel="Custom"
        android:imeActionId="666"
        android:inputType="text"/>

and I've checked the effect with the different API levels both in portrait and landscape mode. Here is the outcome.

API level 15 - 4.0.3

In portrait mode the key label is Go and the action id passed to the callback method is 2, accordingly to the imeOptions setting.

In landscape mode the key label/id is Go/2 as the portrait mode, while the button displayed in the input area is Custom/666, accordingly to the imeActionLabel and imeActionId attributes.

API level 16, 17 and 18 - 4.1.2, 4.2.2 and 4.3

Both in portrait and landscape mode the key and the button are displayed with Custom label and are bound to 666 id, ignoring imeOptions attribute.

This mismatch in the behaviour is quite annoying because:

  • with API level >= 16 you can't distinguish between key button and input area button
  • with API level = 15 you can't set any custom text for key button.

Do you know how to obtain this both in API 15 and 16+? Or if there is a way to obtain a consistent behaviour across all (or at least a part of) the API versions?

Maybe I am missing something in the IME settings that can justify the different behaviour...

Thank you very much!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's actually up to the input method app, not the Android framework itself, to decide what to do with the values you set.

The Android framework just passes the values you set through to the input method, which can then choose what buttons to show on the keyboard or an "extracted" EditText in full-screen view. The Android framework influences the EditorInfo in two ways:-

  • It passes it through EditorInfo.makeCompatible to ensure the values therein are compatible between the keyboard's and the app's targetApiVersions. At the moment this only affects some InputType values, not the editor action, but this could change if new editor actions (or completely new settings) are introduced.

  • It sets the default behaviour for the input method, including the behaviour around full-screen editors. If the input method chooses not to override this default behaviour, then it could end up with behaviour that's different between Android versions. Many keyboards do choose to set their own behaviour, in a way that's consistent between Android versions.

For that reason, it's not so simple to say that a certain EditorInfo field has a certain effect on any given version, and there's no way to ensure a consistent behaviour, even on one Android version. All you're doing is providing hints to the input method, which chooses how to present them to the user.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...