How can I automatically clear the text in EditText?

final TextView textView = (TextView) findViewById(;

final EditText editText = (EditText) findViewById(;

Button button = (Button) findViewById(;
button.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        String etString = editText.getText().toString();

I am new to coding and I don’t know how to automatically clear the text in an EditText so the user doesn’t have to do it themselves. You can see in all “big” websites that when you enter text into a text box (for example: “What’s your name?”) you see “first name” in the text box and when you click on it, it disappears. How can I make the text disappear automatically without the user having to delete it manually?

What you’re referring to isn’t actually text that’s being set — it’s a hint (which is why it doesn’t show after the EditText is focused or text has already been entered). You can set these placeholder hints in your EditText XML, for example:

android:hint="First Name". 

If you’re feeling really adventerous, you can also wrap your EditText in a TextInputLayout for a Material Design style floating hint.

If that helps, be sure to accept this answer.

You can do it grammatically by modifying your code to use the hint property:


also you can change color by adding

editText.setHintTextColor(<some color>);