I'm using the new Action Bar Support and all my action views are shown in overflow and not as icons in the bar. My app is for 7+ API.
HomeActivity:
public class HomeActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(R.string.app_name);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
}
home.xml
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item
android:id="@+id/action_browse"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/title_activity_browse"/>
<item
android:id="@+id/action_search"
android:actionViewClass="android.widget.SearchView"
android:icon="@android:drawable/ic_menu_search"
android:showAsAction="ifRoom|collapseActionView"
android:title="@string/text_search"/>
<item
android:id="@+id/action_scan"
android:icon="@drawable/action_scan"
android:showAsAction="always"
android:title="@string/title_activity_browse"/>
I'm deploying on Nexus 7 with 4.3 and on LGP500 with 2.3.3 and no icons. I've also added android:theme="@style/Theme.AppCompat.Light.DarkActionBar" on the manifest and my project is correctly referencing android-support-v7-appcompat as described in the official doc.
A common mistake is forgetting to include the title string in your string.xml file. Make sure you include it for each menu item.
Suppose our menu xml contains the following item :
If we forget to include the value for the string toggle_action, then the action bar icon will not show.
Go to your strings.xml file and add in the following:
you have to define your
menu
resource files with also the attributes for the support library.To implement the back support it reads them instead of the ones defined in older Android version.
NB remeber that for the SearchView class changed. it's now used the one from the support library so you also have to update your code in the onCreateOptionsMenu()
EDIT: here is a pretty good tutorial on how to migrate from ActionBarSherlok to AppCompat