Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView to display hint before text entered

Tags:

android

How do I put text into empty TextView so it goes away when user starts typing? Just like here in StackOverflow under "Tags" field.

Same approach used in GMail client. That will save me some space - no need to create labels..

like image 577
katit Avatar asked May 25 '11 23:05

katit


2 Answers

Throw an android:hint="hint text" into your EditText xml tag.

like image 59
Haphazard Avatar answered Oct 28 '22 09:10

Haphazard


As haphazard said or programatically you can use...

setHint(CharSequence hint) or setHint(int resId).

The equivalent to the resource id in xml would be android:hint="@string/hint_text" (for example).

like image 24
Squonk Avatar answered Oct 28 '22 10:10

Squonk