Search code examples
androidandroid-actionbarandroid-appcompatsearchview

Android: SearchView component change icon (no ActionBar)


How can I change default search icon for SearchView?

<SearchView
   android:id="@+id/searchView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />

I´m not using actionBar. Is it possible? How?


Solution

  • It´s possible to use AppCompat.

    But I used small hack:

    mSearchView = (SearchView) searchViewMenuItem.getActionView();
    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView v = (ImageView) mSearchView.findViewById(searchImgId);
    v.setImageResource(R.drawable.your_new_icon);  
    

    from this How to change the default icon on the SearchView, to be use in the action bar on Android? and it looks ok.