I found that my "bug-like behavior" was due to imeActionLabel
complicating things. I only used it because it was mentioned in the Text Fields Guide as a way to have a custom return key label. Here are the results of my tests in Lollipop,
Case 1: default, return key symbol = closing angle bracket
<EditText
android:singleLine="true"
android:inputType="textUri"/>
onEditorAction is called once.
- KeyEvent = null, actionId = 5 =
EditorInfo.IME_ACTION_NEXT
- if return true, cursor remains in EditText, keyboard open
- if return false, cursor moves to next focusable, keyboard open if
necessary
Case 2: imeOptions
, return key symbol = checkmark
<EditText
android:singleLine="true"
android:inputType="textUri"
android:imeOptions="actionDone"/>
onEditorAction is called once.
- KeyEvent = null, actionId = 6 =
EditorInfo.IME_ACTION_DONE
- if return true, cursor remains in EditText, keyboard open
- if return false, cursor remains in EditText, keyboard closes
Case 3: imeActionLabel
, return key symbol = "URdone"
<EditText
android:singleLine="true"
android:inputType="textUri"
android:imeOptions="actionDone"
android:imeActionLabel="URdone"/>
onEditorAction can be called more than once.
KeyEvent = null, actionId = 0
- if return true, cursor remains in EditText, keyboard open, onEditorAction is NOT called a second time
- if return false, onEditorAction is called a SECOND time:
KeyEvent = KeyEvent.ACTION_DOWN
, actionId = 0
- if return false, cursor moves to next focusable, keyboard open if necessary, onEditorAction is NOT called a third time
- if return true, onEditorAction is called a THIRD time:
KeyEvent = KeyEvent.ACTION_UP
, actionId = 0
- if return true, cursor remains in EditText, keyboard open
- if return false, cursor moves to next focusable, keyboard open if necessary
NOTES:
I'm not sure if actionId = 0 is from EditorInfo.IME_ACTION_UNSPECIFIED
or EditorInfo.IME_NULL
.
If the next focusable is non-editable, the return key symbol becomes a left pointing arrow.
You can also use setOnFocusChangeListener
to override onFocusChange
, which will be called according to the above cursor behavior.
android-edittext
tag instead ofedittext
:) – Justnessevent
is definitely sometimesnull
, going back to at least Honeycomb. Here is a sample project showing how I useonEditorAction()
: github.com/commonsguy/cw-omnibus/tree/master/ActionBar/… – TrixactionId
may be EditorInfo.IME_NULL, which means the enter key being pressed. – Bibb