Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout EditText nextFocusRight not working as should

I have two TextInputLayout elements side by side: firstname and lastname. Below them I have another full width TextInputLayout element: email.

I'm trying to overwrite the next button on the keyboard so that when clicking Next inside the firstname input, it should go to lastname input and from there to e-email etc.

Now the issue is that when I press Next on the keyboard it's not going to the lastname field but instead going to e-mail below it.

This is part of my xml file where I have these three inputs:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_gravity="center_horizontal"
    android:baselineAligned="false">

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

        <EditText
            android:id="@+id/register_input_firstname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_firstname"
            android:inputType="textCapSentences"
            android:nextFocusForward="@+id/register_input_lastname"
            android:nextFocusRight="@+id/register_input_lastname" />

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

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

        <EditText
            android:id="@+id/register_input_lastname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/hint_lastname"
            android:inputType="textCapSentences"
            android:nextFocusDown="@+id/register_input_email" />

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

</LinearLayout>

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

    <EditText
        android:id="@+id/register_input_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_email"
        android:inputType="textEmailAddress" />

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

I also tried targeting the TextInputLayout instead of EditText but it has no effect.

Is the next focus even possible with TextInputLayout's or is it a bug or am I just doing something very wrong?

like image 973
Karl Viiburg Avatar asked Jan 20 '16 14:01

Karl Viiburg


People also ask

How do I remove the default padding in TextInputLayout?

You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view.

How do I change the line color in TextInputLayout?

You can apply a custom style to change the colors. To change the hint color you have to use these attributes: hintTextColor and android:textColorHint . To change the bottom line color you have to use the attribute: boxStrokeColor .


2 Answers

Change to this --> android:nextFocusDown="@+id/register_input_lastname"

like image 190
Yen Pei Tay Avatar answered Sep 17 '22 23:09

Yen Pei Tay


I used this code below it's working like a magic :)

Actually the trick is

android:imeOptions="actionNext"

android:nextFocusDown="@+id/tilAddress"

android:inputType="text"

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/text_size_small"
            android:textColor="@color/colorTxt"
            android:maxLines="1"
            android:imeOptions="actionNext"
            android:nextFocusDown="@+id/tilAddress"
            android:inputType="text"
            android:hint="School Name" />
    </android.support.design.widget.TextInputLayout>

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

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/text_size_small"
            android:textColor="@color/colorTxt"
            android:maxLines="1"
            android:hint="Address" />
    </android.support.design.widget.TextInputLayout>
like image 25
S.Prapagorn Avatar answered Sep 20 '22 23:09

S.Prapagorn