[ACCEPTED]-Unable to show keyboard automatically in the SearchView-searchview
Accepted answer
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);
}
}
0
I encountered this problem with a SearchView 2 that still would not open the keyboard, and 1 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);
}
}
});
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 1 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.
What about using setOnFocusChangeListener
?
searchview.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
}
});
0
Best and simplest way to do it :
android:focusable="true"
app:iconifiedByDefault="false"
android:focusableInTouchMode="true"
Add above three lines into your xml under 1 SearchView and see the magic....!!
Try:
void focusSearchViewAndOpenOrCloseKeyboard(boolean focus) {
searchView.setIconified(focus);
}
The source shows us that SearchView
handles its own 1 closing and opening of the soft keyboard.
<EditText
android:id="@+id/edt_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:background="@null"
android:ellipsize="end"
android:hint="@string/SERACH"
android:imeOptions="actionSearch"
android:inputType="textVisiblePassword"
android:singleLine="true"
android:textAlignment="viewStart" />
0
add <requestFocus />
in your search view like this
<EditText
android:id="@+id/et_search"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@android:color/transparent"
android:imeOptions="actionSearch"
android:maxLines="1"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textColorHint="#e6e6e6">
<requestFocus />
</EditText>
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.