How do I make an Android EditView 'Done' button and hide the keyboard when clicked?

d-man picture d-man · Dec 17, 2009 · Viewed 126.2k times · Source

When the user clicks on the EditView, Android opens the keyboard so that user can write in the EditView.

The problem is, when the user is done writing, there is no way to hide the keyboard. The user has to press the back button to hide the keyboard.

Is there a way to display a Done button on the keyboard that will hide the keyboard?

Answer

Paresh Mayani picture Paresh Mayani · Jun 28, 2011

First you need to set the android:imeOptions attribute equal to actionDone for your target EditText as seen below. That will change your ‘RETURN’ button in your EditText’s soft keyboard to a ‘DONE’ button.

<EditText 
    android:id="@+id/edittext_done"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="Enter some text"
    android:imeOptions="actionDone"
    android:singleLine="true"
    />