JoJo JoJo - 1 year ago 117
Android Question

How to remove focus from EditText when user is done editing?

I have a single EditText on my layout. After the user inputs some text and hits the "done" key, I would like to remove the blinking cursor from it. I have scoured StackOverflow and found 3 answers that didn't work for me. The blinking cursor still remains.

private class MyOnKeyListener implements OnKeyListener {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& keyCode == KeyEvent.KEYCODE_ENTER) {
// FAIL 0

// FAIL 1
InputMethodManager imm = (InputMethodManager)getSystemService(
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

// FAIL 2

return true;
} else {
return false;

Answer Source

You could use a xml attribute,


or you can do it in code with this method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download