12

I am using floating hint from material design. I want to shift focus from one EditText to the next, So I have put imeOptions="actionNext" in all editTexts and imeOptions="actionDone in the last EditText. But focus is not shifting to next EditText.

Below is the snippet of my xml.

<android.support.design.widget.TextInputLayout
    android:id="@+id/streetWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/TextInputStyle">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Street/Locality *"
        android:imeOptions="actionNext"
        android:maxLines="1"/>

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/flatWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_10sdp"
    android:theme="@style/TextInputStyle">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Building Name / Flat Number*"
        android:imeOptions="actionNext"
        android:maxLines="1"/>

</android.support.design.widget.TextInputLayout>
hiddeneyes02
  • 2,562
  • 1
  • 31
  • 58
rajat44
  • 4,941
  • 6
  • 29
  • 37

4 Answers4

19

You should add android:imeOptions="actionNext" in EditText section.

<android.support.design.widget.TextInputLayout
    android:id="@+id/streetWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/TextInputStyle">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:maxLines="1"
        android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
hiddeneyes02
  • 2,562
  • 1
  • 31
  • 58
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • there is no attribute as ` android:imeOptions=""` in TextnputLayout. – rajat44 May 04 '17 at 10:39
  • yeah same thing . basically `imeOptions` is not an attribute . – rajat44 May 04 '17 at 10:43
  • 1
    sorry sorry , add `android:inputType="text"` and `android:imeOptions="actionNext"`in your EditText section – IntelliJ Amiya May 04 '17 at 10:45
  • 1
    ohh it's working fine now. `android:inputType` did the work. So what I get is all the EditTexts should have `inputType` as their attribute. Thanks – rajat44 May 04 '17 at 11:01
  • If you want more than one line, it is not necessary to add android:maxLines="1" , for example if it is a TextInputLayoutBox: With android:inputType="text" android:imeOptions="actionDone" It's enough – Emmanuelguther Nov 16 '18 at 23:10
  • @IntelliJAmiya How to hide soft keyboard after hit ```actionDone```? – Ganesh MB Jul 05 '21 at 17:26
7

Add attribute android:inputType="text" to your EditText.

Try this:

<android.support.design.widget.TextInputLayout
    android:id="@+id/streetWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Street/Locality *"
        android:imeOptions="actionNext"
        android:maxLines="1"
        android:inputType="text"/>

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/flatWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_10sdp">

    <EditText

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Building Name / Flat Number*"
        android:imeOptions="actionNext"
        android:maxLines="1"
        android:inputType="text"/>

</android.support.design.widget.TextInputLayout>
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
3

You should add android:inputType="text" on section Tag

If you not adding inputType imeOption is not work

Try this :

<android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/dimens_16dp">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/et_impian"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/text_fill_your_dream_here"
                        android:imeOptions="actionNext"
                        android:inputType="text"
                        android:backgroundTint="@color/color_green_manulife"/>

                </android.support.design.widget.TextInputLayout>
1

In my case I had to also add android:nextFocusForward="@id/secondInput". Make sure you are adding id's on TextInputEditText and not on TextInputLayout.

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="First input">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/firstInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="number"
        android:nextFocusForward="@id/secondInput">

        <requestFocus />
    </com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Second input">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/secondInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionDone"
        android:inputType="text"
        android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
Primož Ivančič
  • 1,984
  • 1
  • 17
  • 29