[android] Android EditText Hint

I have set a hint for an EditText, currently the hint visibility is gone. When a user starts typing, I want to remove the hint text, when the cursor is visible in the EditText, not at the time when a user starts to type. How can I do that?

<EditText 
android:paddingLeft="10dp"
android:background="@drawable/edittextbg"
android:layout_marginLeft="4dp"
android:layout_marginTop="7dp"
android:gravity="left"
android:id="@+id/Photo_Comments" 
android:layout_width="150dip" 
android:maxLines="1"
android:hint="Write Caption"
android:maxLength="50"
android:singleLine="true"
android:maxWidth="100dip"
android:layout_height="wrap_content"/>

This question is related to android

The answer is


To complete Sunit's answer, you can use a selector, not to the text string but to the textColorHint. You must add this attribute on your editText:

android:textColorHint="@color/text_hint_selector"

And your text_hint_selector should be:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:color="@android:color/transparent" />
    <item android:color="@color/hint_color" />
</selector>

et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            et.setHint(temp +" Characters");
        }
    });

You can use the concept of selector. onFocus removes the hint.

android:hint="Email"

So when TextView has focus, or has user input (i.e. not empty) the hint will not display.