Search code examples
androidandroid-edittexthint

Android EditText remain hint visible and right-sided


How to make hint in EditText visible during user input and after it? And is it posible to place hint on the right side of EditText control, but user input text - on the left side?

Here is an example what I'm looking for:

Both hint and user input are visible


Solution

  • So I've found pretty simple solution, a bit tricky, but it works - just to to make relative layout with EditText for input and TextView for hint inside:

    <RelativeLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some text"
                android:layout_alignParentLeft="true"
                android:id="@+id/editText2"
                android:layout_gravity="center"
                />
        <TextView
                android:id="@+id/text_hint"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:text="HintText"
                android:textSize="18sp"
                android:layout_marginRight="10dp"
                android:textColor="#808080"
                />
    </RelativeLayout>