In my previous posts we learn some basic characteristics and tab navigation ,

    Leveraging action bar in Android

    Leveraging Action bar in android : Tab Navigation


Now here we learn how to show action bar items in List navigation mode 

The final action bar navigation mode is list navigation. With list navigation enabled, a drop-down spinner widget is in place of the title and subtitle text elements. This is only convention; the action bar will allow a title and navigation list to be displayed at the same time side by side, but there is often not enough visible real estate (at least on a handset device) to effectively display both items.

Note: The implementation here is implemented using AppCompat  Support Library v7 , but it can be easily modified to work with native API’s . The only changes are that each activity must extend Activity instead of ActionBarActivity, and each call to getSupportActionBar() should be replace to getActionBar(). 


1.       Ellipse SDK

2.       Android SDK

3.       ADT plugin

Or Android Studio and a compatible version of JAVA SDK

Install and configure the above utilities.

Now create a new Android project namely “ActionBarApplicationTest”. 

Implementation objective:

To show the list navigation mode for Action bar items where the items are displayed in drop down list view on action bar.

Code Implementation: 

First of all update your activity_main. xml as follows:

<LinearLayout xmlns:android=""

        android:textSize="28dp" />

 Now navigate to and add this code:

package com.example.msclient010.actionbarapplicationtest;

import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends ActionBarActivity implements {

//adapter for holding the list navigation
 ArrayAdapter<String> adapter;
    protected void onCreate(Bundle savedInstanceState) {
        //getting action bar instance actionbar = getSupportActionBar();
        //Enables taps on the home logo
        //Display home with the "up" arrow indicator
        //Set the Title text
        actionbar.setTitle("My Title");
        //Set the sub title
        //List navigation
        //Apply the appropriate theme to ActionBar item views
        Context context = getSupportActionBar().getThemedContext();
        //Add list items to be displayed on action bar in a list
        List<String> spinnerItem = new ArrayList<>();

        //Creating an array adapter to hold list items
        adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, spinnerItem);
        //setting adapter to drop down list view
        //Attach a selection listener
        actionbar.setListNavigationCallbacks(adapter, ( this);
        //apply navigation list mode to action bar
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == {
            return true;
        return super.onOptionsItemSelected(item);
    /* OnNavigationListener Callback Methods */
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        //getting text view reference for text to be displayed on Screen
        TextView txt = (TextView) findViewById(;
        //Getting the selected item text from the list
        String itemTxt = adapter.getItem(itemPosition).toString();
        //setting the selected item text to main text
        return true;

Code Explanation: 

·         To enable the list, we must only pass the adapter we’ve created and an OnNavigationListener callback to react to selection events, and then set the navigation mode on the action bar.

·         We create a drop-down spinner by using the standard adapters and resources from the framework, and we create a simple static list of creatively named items.

·         Take note of the Context we pass into the ArrayAdapter instance. Normally, we would just use the activity and pass a this pointer into the constructor.

·         However, it is common that the action bar uses a slightly different set of themes or styles to display itself (one such theme is Theme.Holo.Light.DarkActionBar) than the rest of the activity uses. This can create visual elements that don’t look correct as action bar elements.

·         To avoid this problem, we pass the Context offered by getThemedContext(), which provides the appropriate styles for widgets inflated into the action bar 

Running the application:

Hit on run button,


Click on the item next to title bar, a drop- down list will appear consists of action bar items



Select on any item the corresponding view will be shown on the screen 



Next post will involve the locking behavior of UI :Locking Activity Orientation in Android 

Thanks for reading this post.

Happy Coding!! J


  Modified On Mar-24-2018 03:54:43 AM

Leave Comment