Tijo Joseph
Tijo Joseph

Reputation: 241

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

Upvotes: 20

Views: 8774

Answers (5)

Bruce Wayne
Bruce Wayne

Reputation: 495

In Kotlin you can also set

isSingleLine = true

Upvotes: 0

mathew11
mathew11

Reputation: 3590

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.

Upvotes: 16

Mathieu Perroud
Mathieu Perroud

Reputation: 11

Hi you can programmatically set :

EditText edit = view.findViewById(R.id.memo_edit_text);
edit.setRawInputType(InputType.TYPE_CLASS_TEXT);
edit.setImeActionLabel("DONE", EditorInfo.IME_ACTION_DONE);
edit.setImeOptions(EditorInfo.IME_ACTION_DONE);

On the EditText that you want to associate with an IME Action
It works for textMultiLine and with any digits, just chose your action

credits : https://stackoverflow.com/a/52503760/11858207

Upvotes: 1

angryITguy
angryITguy

Reputation: 9561

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;
            }
        }); 

Upvotes: 2

Ranjithkumar
Ranjithkumar

Reputation: 18416

Just add singleLine="true" to your edittext

  android:singleLine = "true"

Upvotes: 29

Related Questions