Spinner menu

The spinner menu is a navigation mode that allows you to switch from one view to another using a drop down menu.
The advantage of using the spinner menu consists in a more compact design because it does not require a dedicated tab bar, but it uses the bar already commonly used for the title and the logo of the application.
According to the Google guidelines for action bar the spinner menu should be used to show different views that show the same data but arranged and filtered in a different way (calendar by day, week or month) or that show the same data type (for example, the contents of multiple accounts).
The following is an example implementation of a spinner menu to show 2 fragments.

  1. create an Android project without a starting Activity
  2. edit the file AndroidManifest.xml
  3. edit the file res/values/strings.xml
  4. create the 2 resources for the layouts res/layout/tab1.xml and res/layout/tab2.xml

  5. create the class eu/lucazanini/spinnermenu/

    in this class you can see:

    • you enable the NAVIGATION_MODE_LIST for the action bar
    • you hide the title to get more space for the menu
    • you create an object of the class ArrayAdapter that implements the interface SpinnerAdapter using an array of strings defined in a resource file
  6. create the classses eu/lucazanini/spinnermenu/ and eu/lucazanini/spinnermenu/

  7. launch the app

Action Bar
Implementing Lateral Navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.