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
Android SearchView setOnQueryTextListener(OnQueryTextListener listener) Sets a listener for user actions within the SearchView.
Android SearchView provides user interface to search query submitted over search provider. SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class.
To make the SearchView expanded by default, call setIconifiedByDefault(false) on it when you initialise it (e.g. in onCreateOptionsMenu(..) or onPrepareOptionsMenu(..) ). I've found in most cases this will give it focus automatically, but if not simply call requestFocus() on it too.
Add the Search View to the App Bar To add a SearchView widget to the app bar, create a file named res/menu/options_menu. xml in your project and add the following code to the file. This code defines how to create the search item, such as the icon to use and the title of the item.
Try this:
searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With