Unable to show keyboard automatically in the SearchView
If you are using SearchView:
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:iconifiedByDefault="true"
app:showAsAction="always"
app:iconifiedByDefault="true"/>
Then just add it to your onCreate method :
final SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
It works for me.
I encountered this problem with a SearchView that still would not open the keyboard, and was able to do so by adding a 200ms delay:
mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(final View view, boolean hasFocus) {
if (hasFocus) {
view.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view.findFocus(), 0);
}
}, 200);
}
}
});
Fixed!
mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
showInputMethod(view.findFocus());
}
}
});
And
private void showInputMethod(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(view, 0);
}
}