Search code examples
javaandroidsearchview

Android Search View Ignoring searchHintIcon - searchHintIcon Blurry


I'm trying to hide the searchHintIcon using some code I found here on SO.

My Search View Theme:

<style name="SearchViewTheme" parent="Base.Widget.AppCompat.SearchView">
    <item name="android:textColorHint">@android:color/white</item>
    <item name="android:searchHintIcon">@null</item>
</style>

My Search View XML Code:

<SearchView
  android:id="@+id/search_view"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentTop="true"
  android:layout_toEndOf="@+id/iVProfilePicture"
  android:searchIcon="@drawable/search_icon"
  android:theme="@style/SearchViewTheme">
</SearchView>

My main reason for hiding the Icon is that it shows up really blurry when the search view is Uncollapsed:

Search View Bug

For comparison here is the collapsed search view:

Normal Search

Any Ideas how I'm able to:

a) hide the hint icon or b) unblur the hint icon

Thanks in advance!


Solution

  • so , knowing that you are adding your searchView in the actionbar , you can proceed like that :

    1- First : Inside the xml folder in res , create a an xml file : searchable.xml and give it a label and a hint

    <searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="Search"
    android:hint="Search" >
    </searchable>
    

    2- secondly: Add your searchView in the main menu of you're application, in the menu folder create your menu xml file, for exemple main.xml and add you're searchView

     <item
        android:id="@+id/search"
        android:title="Search"
        app:showAsAction="always"
        android:icon="@drawable/ic_action_search"
        app:actionViewClass="android.support.v7.widget.SearchView" />
    

    3 Thirdly: in your activity , Override the methode onCreateOptionsMenu, and add the code for the searchView

    SearchManager manager = (SearchManager) 
    getSystemService(Context.SEARCH_SERVICE);
    SearchView search = (SearchView) menu.findItem(R.id.search).getActionView();
    search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    

    and if you want to manage the search, you can also add :

    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }
    
            @Override
            public boolean onQueryTextChange(String newText) {
                // when a user is typing text in the searchView
                return false;
            }
        });
    

    4-Fourth : in you're Manifest File add the following codes: -- in the the activity where you are doing you're search, add this :

     <activity android:name=".YourActivity">
    <intent-filter>
         <action android:name="android.intent.action.SEARCH" />
    </intent-filter>
    
    <meta-data
        android:name="android.app.default_searchable"
        android:value=".YourActivity" />
    <meta-data
        android:name="android.app.searchable"
        android:resource="@xml/searchable" />
    </activity>
    

    You're searchView icon will be invisible or blur when you are doing you're search. Sorry I know maybe you haven't need all this, but maybe it will be beneficial for others too.