Search code examples
androidmenuspinnerpopupmenu

Show triangle inside the view that opens a popupmenu (like with a spinner)


I have a ListView which handles onClick events by showing a PopUpMenu. However, I want the user to see the little triangle inside the views that can be clicked.

I tried using a Spinner, because that element looks like what I'm after, but I can't set the title of the Spinner to anything other than its options.

Of course I could custom make everything but as this is not a new pattern I thought maybe there's already something out there. I just can't find it myself.

Example of what I'm after:

spinner example


Solution

  • If you use ActionBarSherlock, you can use the triangle ABS uses:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
        <TextView
            etc />
    
        <ImageView
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:contentDescription="@string/expand_triangle"
            android:src="@drawable/abs__spinner_ab_default_holo_light" />
    
    </RelativeLayout>