In onCreate()
I set :
searchView.setOnQueryTextListener(this);
searchView.setQuery("example text", false);
In Material Design when I open the activity it automatically opens keyboard(without clicking on SearchView)
But when I'm trying the same on non material design android device it fortunately does not automatically open the keyboard.
So how to disable automatically opening of keyboard in onCreate
for Material Design android devices?
Add this method and call it in your onCreate after your layout has been inflated.
private void closeKeyboard() {
View currentFocus = this.getCurrentFocus();
if (currentFocus!=null){
android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager)this.getSystemService(android.content.Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
}
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}