Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading