Reputation: 977
Hi guys i was assigned a task in my project,there i need to add a Done button on the top of Android keyboard.In my screen i have an EditText,whenever i click on the EditText it should open a keyboard along with the "Done" Button on the top of an Android keyboard.So that i can attach a Listener to that button to perform my task.Any Suggestions.
Thanks&Regards, E.N.Krishna.
Upvotes: 0
Views: 1752
Reputation: 632
If you need the keyboard to display the Done button, you need to define this in your EditText
<EditText android:text="EditText" android:layout_width="fill_parent"
android:id="@+id/editText1" android:layout_height="wrap_content"
android:imeOptions="actionDone"/>
You can then catch when the user presses the Done button by using OnEditorActionListener
class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
}
Upvotes: 2