2

Here snippet:

 searchViewEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        searchViewEditText.setSingleLine(true);

As result when keyboard open, the button Done is show. OK.

Here result:

done

But when I click on button Done nothing happen. I expect that keyboard will be hide.

STF
  • 1,485
  • 3
  • 19
  • 36
Alex
  • 633
  • 1
  • 7
  • 18
  • go through to this [https://stackoverflow.com/a/5677676/5308778](https://stackoverflow.com/a/5677676/5308778), here you can get callback after pressing done button. – yashkal Nov 16 '17 at 10:20

2 Answers2

2

You can use this (sets a special listener to be called when an action is performed on the EditText), it works both for DONE and RETURN:

max.setOnEditorActionListener(new OnEditorActionListener() {
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
            Log.i(TAG,"Enter pressed");
        }    
        return false;
    }
});
Anjal Saneen
  • 3,109
  • 23
  • 38
0

I think that you will have to close the Keyboard programatically. To do so, add the following logic to the TextView Listener:

editText = (EditText) findViewById(R.id.edit_text);

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
               //Replace <<active view>> With the active view
                inputMethodManager.hideSoftInputFromWindow(<<active view>>.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

I hope this helps you :)