Search code examples
androidandroid-edittexttextview

Put TextView inside EditText


Please tell me, how i can to put text inside a EditText like this

image

And only right text can be edit.


Solution

  • Keep TextView and EditText inside Relative Layout and Adjust them according to your requirement.

    Example:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <EditText
            android:id="@+id/Edittext"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="20dp"
            android:ems="10"
            android:hint="To my first character" >
    
            <requestFocus />
        </EditText>
    
        <TextView
            android:id="@+id/text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/Edittext"
            android:layout_alignBottom="@+id/Edittext"
            android:layout_alignParentRight="true"
            android:text="123123" />
    
    </RelativeLayout>
    

    Change it if you have any changes