Tuesday, 23 September 2014

Android Menu showAsAction Ignored

While working on a menu definition in Android you have the option to specify if the menu items should be visible as icons or should be hidden in the overflow menu (the three dots at the end of the action bar). This can be achieved with the showAsAction attribute in the menu XML definition. As a default the menu items are hidden in the overflow menu.

Today this attribute was simply ignored by my Android app. This is what my menu item definition looked like:


But the item was not shown as an icon on the action bar. As you can see I'm using a custom namespace for the showAsAction attribute. The namespace is defined as:


This is required if you are working with the compat library. What I didn't know, that was causing the issue, is that when you use the showAsAction with the custom namespace your Activity must extend the support ActionBarActivity, otherwise the attribute will just be ignored.