2

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?

  • Have you seen this question? It looks like it has what you need: https://stackoverflow.com/questions/5014219/multiline-edittext-with-done-softinput-action-label-on-2-3 – davehenry Jan 03 '22 at 06:34

1 Answers1

1

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)
Mayur Gajra
  • 8,285
  • 6
  • 25
  • 41