Search code examples
androidandroid-layoutlayouttextviewandroid-edittext

How to divide text in EditBox as TextView and EditBox in Android Layout


I want my EditText to look like these - enter image description here I am able to achieve the EditText but I am not able to keep a TextView aside it.

here is my code -

<LinearLayout
        android:id="@+id/input_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_marginBottom="50dp"
        android:layout_alignParentBottom="true"
        android:gravity="center">

    <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="@android:color/white"
            android:hint="Username"
            android:background="@drawable/rounded_edit_text" />

    <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="@android:color/white"
            android:hint="Password"
            android:background="@drawable/rounded_edit_text" />
</LinearLayout>

Solution

  • Try this

    <LinearLayout
            android:layout_width="250dp"
            android:layout_height="40dp"
            android:background="@drawable/linear_bg"
            android:orientation="horizontal">
    
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight=".4"
                android:gravity="center"
                android:padding="5dp"
                android:text="UserName"
                android:textColor="@android:color/white" />
    
        <EditText
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight=".6"
                android:background="@android:color/transparent"
                android:gravity="center"
                android:hint="******"
                android:padding="5dp"
                android:textColor="@android:color/white"
                android:textColorHint="@android:color/white" />
    
    </LinearLayout>
    

    drawable/linear_bg

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
        <solid android:color="#3F51B5" />
        <corners android:radius="20dp" />
    </shape>
    

    OUTPUT

    enter image description here

    OUTPUT in device