Android: display the TextView on the right side of the EditText, which is in the TextInputLayout

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

In the above figure, the password field is in TextInputLayout, and on the right side there is also a TextView indicating the action "Forget password".

I get an EditText with a Textview without a TextInpt layout as shown below using a 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 to EditText, I cannot achieve this.

How do I solve this problem?

+9
source share
3 answers

- Surround ,

    <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>

:


, .

+11

border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="0.2dp"
        android:color="@color/color_secondary" />
    <solid android:color="#fff" />

    <padding android:bottom="8dp" />
    <padding android:top="8dp" />
    <padding android:left="8dp" />
    <padding android:right="8dp" />


</shape>

**** .. ****

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/border"  **apply drawable here**
        android:orientation="horizontal">

    <EditText
        android:id="@+id/etxt_password_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:hint="Password"
        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_centerVertical="true"
            android:text="forget ?"
            android:textSize="12sp"
            android:textColor="#808080" />

    </RelativeLayout>

,

0

I try as shown below and works for me. maybe this can help you. Somehow I cannot use TextView inside TextInputLayout, the layout becomes crash. But I can use ImageViews inside it.

<android.support.design.widget.TextInputLayout
    android:id="@+id/layoutTextInput"
    style="@style/CommonTextInputLayout"
    android:textColorHint="@color/aluminium">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        <EditText
            android:id="@+id/editTextValue"
            style="@style/CommonEditText"
            android:imeOptions="actionNext"
            android:layout_marginBottom="8dp"
            android:inputType="text"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-40dp"
            android:src="@drawable/ic_tick_green"/>
    </LinearLayout>
</android.support.design.widget.TextInputLayout>
0
source

Source: https://habr.com/ru/post/1668523/


All Articles