Search code examples
androidandroid-layoutandroid-edittextandroid-textinputlayout

Android: Display TextView in the right-side of EditText which is in the TextInputLayout


I am trying to create a layout like in the picture belowenter image description here

In the above picture the password field is in the TextInputLayout and it also have a TextView in the right side , which points to the Forget Password Activity.

I achive EditText with Textview without TextInpt layout like below using relative layout

enter image description here

XML layout:

        <EditText
            android:id="@+id/email_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_email"
            android:drawableStart="@drawable/ic_email"
            android:drawablePadding="10dp"
            android:hint="@string/email_address"
            android:textSize="14sp"
            android:maxLines="1"
            android:inputType="textEmailAddress" />



        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        <EditText
            android:id="@+id/etxt_password_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_password"
            android:drawableStart="@drawable/ic_password"
            android:drawablePadding="10dp"
            android:textSize="14sp"
            android:hint="Password"
            android:layout_alignParentLeft="true"
            android:inputType="textPassword"
            android:maxLines="1"/>

            <TextView
                android:id="@+id/txt_forget_password"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:text="forget ?"
                android:textSize="12sp"
                android:layout_marginRight="10dp"
                android:textColor="#808080"
                />

        </RelativeLayout>

But If I add TextInputLayout in the EditText I can't achieve it.

How I resolve this issue?


Solution

  • Try Like this - Surround with Relative or Linear Layout to get the output like that

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Password"/>
    
            </android.support.design.widget.TextInputLayout>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:text="Forgot Password ?"/>
        </RelativeLayout>
    

    Note : Set some padding right for edit text for alignment


    If you type full edittext , the textview overlay for your character .