Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications
by James Talbot, Justin McLean, Jorge Hernandez
Creating an Action Bar
You use the same XML to specify menus and action bars. You control which menu item shows in the action bar by setting the android:showAsAction attribute. Setting this to always means it will always show as an action; setting it to ifRoom means it will show if there is room, and setting it to withText means the menu text will also show if there is room.
Let’s create an action bar for the On Your Bike application and see how it is displayed in various flavors of Android.
1. Open the activity_settings menu. Add a new attribute to show an icon for the action bar item, and change showAsAction to be always|withText. Use one of the standard Android icons for the settings icon (see Listing 5.16).
Listing 5.16 Action Bar Menu Item ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access