CantThinkOfAnything
CantThinkOfAnything

Reputation: 1179

Is there a way to hide the keyboard without losing the focus of the EditText

When you click the back button, the keyboard hides itself but the focus on the edittext remains. How can I reproduce this behaviour?

Upvotes: 0

Views: 161

Answers (1)

Basu
Basu

Reputation: 763

You can use this code to hide the keyboard:

getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);

Or this one :

View view = this.getCurrentFocus();
if (view != null) {  
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

If the EditText loses the focus, simple write a simple command

editText.requestFocus();

Upvotes: 1

Related Questions