Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edittext imeOptions actionDone not working with digits attribute?

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

like image 541
Tijo Joseph Avatar asked Feb 27 '17 08:02

Tijo Joseph


3 Answers

Just add singleLine="true" to your edittext

  android:singleLine = "true"
like image 57
Ranjithkumar Avatar answered Nov 11 '22 05:11

Ranjithkumar


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.

like image 29
mathew11 Avatar answered Nov 11 '22 04:11

mathew11


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;
            }
        }); 
like image 1
angryITguy Avatar answered Nov 11 '22 05:11

angryITguy