Behaviour of imeOptions, imeActionId and imeActionLabel
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'stargetApiVersion
s. At the moment this only affects someInputType
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.
Just call .setImeActionLabel()
programtically in java codes to set actionID (again) to your desired one.
editText.setImeActionLabel(getString(R.string.xxx), EditorInfo.IME_ACTION_GO);
When you start a new Android project, it provides a good hint to your question. There is an Activity called LoginActivity
which you can create as a default login screen. This Activity will produce an EditText
as so:
<EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/prompt_password" android:imeActionId="@+id/login" android:imeActionLabel="@string/action_sign_in_short" android:imeOptions="actionUnspecified" android:inputType="textPassword" android:maxLines="1" android:singleLine="true"/>
Now if you read the documentation, you would know that the imeOptions
attribute allows you to specify additional actions for a text field. For example, the keyboard that pops up has an action on the bottom right corner like "Next". Using imeOptions
you can select another action from a predefined list provided by Android. You can specify something like "actionSend" or "actionSearch".
Once you do that, in order you Activity, you can listen for that action using the setOnEditorActionListener
event handler:
mPasswordView = (EditText) findViewById(R.id.password); mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { if (id == R.id.login || id == EditorInfo.IME_NULL) { attemptLogin(); return true; } return false; } });
Notice how we target the imeActionId
here. It is another method to target that EditText
in your Activity, while also having the flexibility to change the action on the keyboard input.