Reputation: 5830
I have the following code:
if(mSearchView != null){
mSearchView.setIconifiedByDefault(false);
mSearchView.setIconified(false);
mSearchView.setOnQueryTextListener(this);
int searchPlateId = mSearchView.getContext().getResources()
.getIdentifier("android:id/search_plate", null, null);
View searchPlateView = mSearchView.findViewById(searchPlateId);
if (searchPlateView != null) {
searchPlateView.setBackgroundColor(getResources().getColor(R.color.white));
}
}
The problem is that the moment I setIconified(false) on the serachview, the keyboard pops up, and I do not want this to happen. Is it possible to prevent this somehow? PS: I Have this in the manifest:
android:windowSoftInputMode="adjustNothing|stateHidden"
Also do it programmatically in onCreate but no luck
Upvotes: 7
Views: 10153
Reputation: 715
Just make Search View Iconified to true.
mSearchView.setIconified(true);
Upvotes: 0
Reputation: 228
Programmatically remove all the fields like
searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();
and set through xml attributes for serach view:
<!-- Dummy item to prevent Search view from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<android.support.v7.widget.SearchView android:id="@+id/serach_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="@id/serach_view"
android:nextFocusLeft="@id/serach_view"/>
It will work.
check this link for reference enter link description here
Upvotes: 2
Reputation: 1
searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();
Upvotes: 0
Reputation: 931
I was also having the same issue . I spend lots of hours for this issue and finally i created a dummy EditText which was hidden in xml and requested focus for the edit text in java code
mSearchView.setFocusable(false);
mSearchView.setIconified(false);
mSearchView.clearFocus();
EditText editText = (EditText) findViewById(R.id.dummy);
editText.requestFocus();
hope it will helpful for someone
Upvotes: 1
Reputation: 1731
Try this:
searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();
Upvotes: 12
Reputation: 5830
I used instead a edittext, and made the functionality of the search icon and close icon myself. This way, I do not have to set "setIconifiedByDefault" being a edittext. and it resolves all my issues
Upvotes: 0