Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Edit Text hint appear when typing

I would like for my app to be able to display different hints in the edittext at different times, so i have to set the hint pro-grammatically at each times as below.

editText.setHint("Hint 1");

But the problem is when i starts typing the hint starts disappearing.I want to show this hint every time.If i set the hint in xml it will not disappear while typing, but how to do this in my case.

like image 239
KJEjava48 Avatar asked Oct 05 '16 06:10

KJEjava48


2 Answers

Either you should consider to change to TextInputLayout(Strongly recommended this. Here is an example too.)

or

make relative layout with EditText for input and TextView for hint inside.Change the textview according to your needs.

<RelativeLayout
        android:orientation="vertical"
        android:layout_width="match_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/editText1"
            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="yourHint"
            android:textSize="14sp"
            android:layout_marginRight="10dp"
            android:textColor="@color/customColor"
            />
</RelativeLayout>
like image 67
Alex Chengalan Avatar answered Sep 28 '22 22:09

Alex Chengalan


what you are expecting is not possible,since we have to how what user is writing on editext. Now a days https://github.com/hardik-trivedi/FloatingLabel this type of hints are more popular,you can try above link.

like image 25
Ravi Sahu Avatar answered Sep 28 '22 23:09

Ravi Sahu