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

前端 未结 3 1701
故里飘歌
故里飘歌 2021-02-20 13:18

I am trying to create a layout like in the picture below

In the above picture the password field is in the TextInputLayout and it also have a TextView in the right side

相关标签:
3条回答
  • 2021-02-20 13:58

    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 .

    0 讨论(0)
  • 2021-02-20 14:11

    Yes it is possible

    Create a drawable

    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>
    

    ****In your code..****

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

    finally adjust your layout as you need

    0 讨论(0)
  • 2021-02-20 14:16

    I am trying like below and it is working for me. may be it may help you. Somehow I am unable to use TextView inside TextInputLayout, layout getting crash. But i am able to 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 讨论(0)
提交回复
热议问题