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


Question

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?

1
102
5/20/2015 10:32:31 PM

Accepted Answer

Use TextView.setImeOptions and pass it actionDone. like textView.setImeOptions(EditorInfo.IME_ACTION_DONE);

127
12/22/2014 5:16:14 AM

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"
    />

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon