I have an Editext . It contains attribute digits and imeOptions (actionDone) together.
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_text_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="1234567890abcdefghijklmnopqrstuvwxyz....."
android:hint="@string/item_name"
android:imeOptions="actionDone"
android:maxLines="1" />
The actionDone (Done button in Softkeyword) not found while using digit && imeOptions attributes together . We can only find enter button which doesn't make any focus change. I have tried it by skipping digit attribute , then imeOptions working correctly. Thanks in advance
Just add singleLine="true" to your edittext
android:singleLine = "true"
Use setRawInputType()
on your EditText View
view.setRawInputType(view.getInputType() & ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)
It is important to call setRawInputType()
and not setInputType()
, since the latter will set the keylistener based on the inputmethod and your android:digits
attribute will be discarded. setRawInputType()
will only change the inputmethod and it won't touch the KeyListener, furthermore & ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
will disable the multi line mode, so no return key will be visible, instead your chosen imeOption should be visible.
Basically, there is a different behavior of singleLine and maxLines.
My testing with "android:digits" seems to cause problems in edittext fields and when setting imeOptions to android:imeOptions="actionDone" I could not get the "Done" button to appear on the keyboard.
Once I used
android:inputType="text"
without digits setting, the keyboard then presented "Done" (or a tick depending on your device's keyboard), and I could then capture the key stroke using:
editextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
int result = actionId & EditorInfo.IME_MASK_ACTION;
switch(result) {
case EditorInfo.IME_ACTION_DONE:
// put your code here.
break;
}
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With