Jamsheed Kamarudeen
Jamsheed Kamarudeen

Reputation: 728

Button collapses even though there is space in Action bar

I wanted to implement a SearchView or a searchDialog in my project, So i edited my main_menu.xml file to look like this

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >

<item
    android:id="@+id/btn_action_bookmark"
    android:icon="@drawable/ic_bookmark"
    android:title="@string/bookmark_label"
    android:visible="false"
    app:showAsAction="always|collapseActionView"/>
<item
    android:id="@+id/btn_action_un_bookmark"
    android:icon="@drawable/ic_un_bookmark"
    android:title="@string/un_bookmark_label"
    android:visible="false"
    app:showAsAction="always|collapseActionView"/>
<item
    android:id="@+id/btn_action_remove"
    android:icon="@drawable/ic_remove"
    android:title="@string/remove_label"
    android:visible="false"
    app:showAsAction="always|collapseActionView"/>
<item
    android:id="@+id/btn_action_download"
    android:icon="@drawable/ic_download"
    android:title="@string/download_label"
    android:visible="false"
    app:showAsAction="always|collapseActionView"/>
<item
    android:id="@+id/menu_search"
    android:icon="@drawable/ic_btn_search"
    android:title="@string/action_bar_button_search"
    android:visible="true"
    android:showAsAction="always"/>
<item
    android:id="@+id/menu_item_share"
    android:title="@string/share_label"
    app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
    app:showAsAction="always"/>

Here, The 2nd last one is the search one. If i swap between that and share, the app crashes and doesnt open. If i do like this, I get the search option collapsed.

Screenshot

Why does this happen? There is no code that says to collapse it. I have an Actionbarparentactivity that extends actionbaractivity (support), and a homeactivity that implements actionbarparentactivity where the nav drawer is implemented, and anotheractivity which implements homeactivity. There is another activity later in the app which implements actionbarparentactivity directly without the nav drawer things, there also, search button is collapsed.

Upvotes: 1

Views: 293

Answers (1)

Blo
Blo

Reputation: 11988

I think the issue is caused by android:showAsAction. You forgot the custom prefix attribute:

<item
    android:id="@+id/menu_search"
    android:icon="@drawable/ic_btn_search"
    android:title="@string/action_bar_button_search"
    android:visible="true"
    app:showAsAction="always" />   <--- on this line

Upvotes: 1

Related Questions