19

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

Tijo Joseph
  • 231
  • 2
  • 7

5 Answers5

29

Just add singleLine="true" to your edittext

  android:singleLine = "true"
Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159
15

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.

Kyle R
  • 99
  • 2
  • 12
mathew11
  • 3,382
  • 3
  • 25
  • 32
  • Worked for me. Thank you. – Tran Hoai Nam Jun 01 '18 at 03:56
  • 1
    **This answer must be marked as accepted!** The `~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE` works even if `android:inputType` and `android:digits` are defined! – gts13 Oct 02 '18 at 07:37
  • As the only answer I've found that doesn't use the deprecated singleLine, this deserves more upvotes – Dave S Oct 04 '18 at 23:03
  • view.setRawInputType(view.getInputType() & ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) you can set edittext.setRawInputType(edittext.getInputType() & ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE) Tested it works! on lousy Mi devices, that using ContextThemeWrapper with NumberFormatException error can try this. Any soft keyboard that doesn't work when IME_ACTION_DONE is set but keyboard doesnt disappear and trigger IME_ACTION_DONE can try this ! This solution is working! – SY MY Aug 31 '22 at 03:17
1

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;
            }
        }); 
angryITguy
  • 9,332
  • 8
  • 54
  • 82
1

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

0

In Kotlin you can also set

isSingleLine = true
Bruce Wayne
  • 435
  • 3
  • 7