Search View uses app icon instead of logo

Android documents explain that app logo is used everywhere when it is defined. But when the search view expands, app icon is used instead of app logo and I can't find a way to show app logo when search view is in expanded state.

Here are the relevant parts.

Manifest file

    android:theme="@style/Theme.MyTheme" >

searchable.xml (setting icon doesn't change anything)

<searchable xmlns:android=""
    android:hint="@string/search_hint" >


<menu xmlns:android="" >

        android:showAsAction="always|collapseActionView" />

Activity Code

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());

NOTE: I use ABS SearchView but same thing happens when I switch to default SearchView.

EDIT : I added some screenshots for clarity.

Here I used the star image for app logo, and android image for app icon. The first screenshot is the default view of activity. The second one is the view when I click search button. It shows the android image while I expect it to be the star image.


Set the logo drawable as your icon. Via theme attribute

<item name="android:icon">@drawable/ab_logo</item>

or in code


You're using a completely different SearchView you declared in menu.xml.

With this code you create new SearchView, which is not what you want.

SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());

So try creating menu like this.

this.getSupportMenuInflater().inflate(, menu);
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
final MenuItem searchItem = menu.findItem(;
final SearchView searchView = (SearchView) searchItem.getActionView();

And for the ActionBar, instead of setDisplayUseLogoEnabled(true) and others, try set all options at once

final ActionBar bar = getSupportActionBar();
        ActionBar.DISPLAY_SHOW_TITLE |
        ActionBar.DISPLAY_USE_LOGO |
        ActionBar.DISPLAY_SHOW_HOME |

This is the setup I have in my current project and never experienced any problems like these.

I had the same problem and I solved it using the following code:

// Your Activity/Fragment must implement the MenuItem.OnActionExpandListener interface

public boolean onMenuItemActionExpand(MenuItem item) {
    return true;

Let me know how this works for you.

I achieved the solution with this simple logic:

public boolean onOptionsItemSelected(MenuItem item) {
            return true;
        return super.onOptionsItemSelected(item);

To replace the icon with a logo, specify your application logo in the manifest file with the android:logo attribute, then call setDisplayUseLogoEnabled(true) in your activity.

refer this document1 document2

And please see this answer for more details

Just remove collapseActionView from your menu Xml.

The only thing you need to have set is this (in onCreate of activity):


...not there is also a setLogo.

Regardless to if you have the icon in the manifest set to something different, this will tell the activity to use a different image during runtime.

I tested this with the following menu item and it works:

  <menu xmlns:android="">

    <item android:id="@+id/menu_search"


Inflated like normal in onCreateOptionsMenu:

getSupportMenuInflater().inflate(, menu);

I had the same problem, (for ABS) I had:

    ActionBar actionBar = ((SherlockFragmentActivity) activity).getSupportActionBar();

And I just added:


And the issue is gone.

I found the best way to solve this problem was to add the SearchView programatically to the menu like this:-

    SearchView searchView = new SearchView(getActionBar().getThemedContext());
            .setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                public boolean onMenuItemActionExpand(MenuItem item) {

                    return true;

                public boolean onMenuItemActionCollapse(MenuItem item) {
                    return true;
            .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItem.SHOW_AS_ACTION_IF_ROOM);

And then use the onActionExpandListener to change the icon/logo to the correct value when then SearchView is expanded.

This solution may also work if you define the SearchView in menu.xml, but you'd then still need to setup the onActionExpandListener() in code to do the same as the above example.


Need Your Help

Where do I set defaults for an associated entity in an embedded Symfony2 form?

php symfony2 doctrine2

I have an entity with a OneToOne association to another entity. For these purposes I'll call the initial entity "Parent" and the associated Entity "Child".

How to reference OneNote interop from Visual Studion 2010

com interop ms-office com-interop

I am trying to use the OneNote interop from visual studio 2010. I have OneNote 2010 installed, I am building a .net 2.0 win forms app. I add a reference, Select the COM tab, and choose either

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.