Search code examples
androidkotlinandroid-edittext

Why does Android multiline EditText with android:imeOptions="actionNext" work in Google Keep?


I'm developing an app that lets you (among the other opportunities) create little notes. Note consists of a title and a body. And the perfect behavior would be to have multiline title with imeOption "actionNext" on a keyboard to move to note content after finishing typing a title.

Official Google docs say, that if you use a multiline EditText, the soft input method's action button will always be a carriage return (https://developer.android.com/training/keyboard-input/style#Action).

BUT! If you'll look at the Google Keep app, you'll see that their notes implement exactly the behavior I need. What's the secret here and how can we implement such behavior in our apps?


Solution

  • You can set imeOptions=actionNext in XML & at runtime setRawInputType to TYPE_TEXT_FLAG_MULTI_LINE. This way you can achieve this behavior.

    According to docs setRawInputType is used for:

    Directly change the content type integer of the text view, without modifying any other state.

    Example:

    XML:

     <EditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionNext"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    

    Activity#onCreate:

    binding.editText.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                    or InputType.TYPE_TEXT_FLAG_MULTI_LINE)