Question

How to get the little gray triangle (indicating a spinner/submenus usually) to a custom action in the ActionBar? I manage to add submenus to my action, but don't see a way to add the small triangle in the lower right corner. (Same when using android.widget.ShareActionProvider)

How I want it (sample from API Demos):

enter image description here

I am able to edit submenus, but not getting the small gray triangle to the lower right of my action icon:

enter image description here

My code for the menu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_new_form"
          android:icon="@drawable/ic_new_form"
          android:title="@string/menu_new_form"
          android:showAsAction="ifRoom|withText">
        <menu>
            <item android:id="@+id/action_sort_size"
                  android:icon="@android:drawable/ic_menu_sort_by_size"
                  android:title="Form 1"
                  android:onClick="onSort" />
            <item android:id="@+id/action_sort_alpha"
                  android:icon="@android:drawable/ic_menu_sort_alphabetically"
                  android:title="Form 2"
                  android:onClick="onSort" />
        </menu>
    </item>
</menu>
Was it helpful?

Solution

I've checked in the sources of Android, and here's how Google implement it:

enter image description here

(it's ic_menu_share_holo_light.png)

So if Google draws this little triangle directly in the icon image, I suppose it's the best practice currently.

OTHER TIPS

That gray triangle in the first picture is available when you set a button to start activity by using Intent.createChooser(intent, "heading").

However, in your technique, you are providing a menu option which contains sub-menus. To make it simple, you may simply create an icon which has a grey triangle at bottom.

example to share a message by asking user to pick option:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT, note.getHead());
share.putExtra(Intent.EXTRA_TEXT, "this is a demo message");

context.startActivity(Intent.createChooser(share, "Share message"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top