bharat
bharat

Reputation: 51

How to show both icon and text in multiple menu items in action bar?

Attached is the screenshot which shows the menu items.enter image description here

Upvotes: 1

Views: 3277

Answers (3)

darshan
darshan

Reputation: 4569

If someone is still looking for an Answer, here's how I got it -

menu.xml

<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">


    <item 
        android:id="@+id/a_More"
        android:icon="@drawable/more"
        android:showAsAction="always"
        android:title="More" >

        <menu>

    <item
        android:id="@+id/MENU_GOTO"
        android:orderInCategory="100"
        app:showAsAction="never" 
        android:showAsAction="never"
        android:icon="@drawable/go_to"
        android:title="Go To Page"/>

        <item
        android:id="@+id/MENU_OUTLINE"
        android:orderInCategory="100"
        app:showAsAction="never" 
        android:showAsAction="never"
        android:icon="@drawable/outline"
        android:title="Table of Contents"/>

    <item
        android:id="@+id/MENU_OPTIONS"
        android:orderInCategory="100"
        app:showAsAction="never" 
        android:showAsAction="never"
        android:icon="@drawable/settings"
        android:title="Settings"/>

    <item
        android:id="@+id/MENU_EXIT"
        android:orderInCategory="100"
        app:showAsAction="never" 
        android:showAsAction="never"
        android:icon="@drawable/exit"
        android:title="Exit"/>

        </menu>
    </item>
</menu>

And in Activity -

@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu);
return super .onCreateOptionsMenu(menu);
    }

Upvotes: 1

pamitha
pamitha

Reputation: 55

     actionBar = getActionBar();

    // Hide the action bar title
    actionBar.setDisplayShowTitleEnabled(false);

    // Enabling Spinner dropdown navigation
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    // Spinner title navigation data
    navSpinner = new ArrayList<SpinnerNavItem>();
    navSpinner.add(new SpinnerNavItem("Local", R.drawable.ic_location));
    navSpinner.add(new SpinnerNavItem("My Places", R.drawable.ic_my_places));
    navSpinner.add(new SpinnerNavItem("Checkins", R.drawable.ic_checkin));
    navSpinner.add(new SpinnerNavItem("Latitude", R.drawable.ic_latitude));     

    // title drop down adapter
    adapter = new TitleNavigationAdapter(getApplicationContext(), navSpinner);

    // assigning the spinner navigation     
    actionBar.setListNavigationCallbacks(adapter, this);

Upvotes: 0

maruti060385
maruti060385

Reputation: 797

http://www.androidhive.info/2013/11/android-working-with-action-bar/

Here the important xml attributes should be known are

android:icon – Defines the icon of the action item.
android:title – Title for the icon.
android:showAsAction – Defines the visibility of the action item. It accepts following values.
always: Forces to display the icon always irrespective of space available. This way is not suggested. withText Displays a text along with the icon. Normally the text value defined by android:title will be displayed

You can use withText for android:showAsAction as below for each of the items which you want to display in action menu. android:showAsAction="withText"

Upvotes: 0

Related Questions