Search code examples
androidbuttonspinner

Customize a Spinner to look like a button


I've got a custom button defined as follows

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" >
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <stroke android:width="1dip" android:color="@color/colorPrimary" />
            <gradient android:angle="-90" android:startColor="@color/colorPrimaryDark" android:endColor="@color/colorAccent"  />
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <stroke android:width="1dip" android:color="@color/colorPrimary" />
            <solid android:color="@color/colorAccent"/>
        </shape>
    </item>
    <item >
        <shape android:shape="rectangle"  >
            <corners android:radius="10dp" />
            <stroke android:width="1dip" android:color="@color/colorPrimary" />
            <gradient android:angle="-90" android:startColor="@color/colorPrimary" android:endColor="@color/colorPrimaryDark"  />
        </shape>
    </item>
</selector>

I'd like to create a spinner which, when not clicked looks like the button, and only when pressed showing the selectable items. The default spinner is not very pretty, and does not fit my design.

Anybody knows how to acheive this?


Solution

  •                             <Spinner
                                android:id="@+id/spinner_start_day_def"
                                android:layout_width="100dp"
                                android:layout_height="30dp"
                                android:layout_gravity="center"
                                android:background="@drawable/rounded_button"
                                android:gravity="center"
                                android:minWidth="70dp"
                                android:popupBackground="@color/colorPrimary"
                                android:textAlignment="center" />
    

    That was easy, android:background="@drawable/rounded_button"