You should remove this value: collapseActionView
Replace this line:
android:showAsAction="always|collapseActionView"
with for example this
android:showAsAction="never"
Question
I am trying to add the Search button to the Android Action bar by following this tutorial: https://developer.android.com/training/basics/actionbar/adding-buttons.html
I modified by minSdkVersion to 11 in my Manifest.
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
I have added the action_search item in a main.xml
file located in the menu
folder:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
android:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView"/>
</menu>
Eclipse has provided the method already for the menu, which I have not changed:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
I've added the string to my strings.xml
: <string name="action_search">Search</string>
and included ic_action_search.png
in my drawable folders.
There are no errors upon launch. I see the Settings menu item in the overflow. But I do not see the search button anywhere.
Solution
You should remove this value: collapseActionView
Replace this line:
android:showAsAction="always|collapseActionView"
with for example this
android:showAsAction="never"