如何在Android中创建自定义Spinner

时间:2016-03-09 06:04:35

标签: android spinner

我想创建如下的自定义微调器:

enter image description here

由于

1 个答案:

答案 0 :(得分:3)

布局:

 <Spinner
                android:id="@+id/spUserType"
                android:layout_width="250dp"
                android:layout_height="30dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_weight="1"
                android:background="@drawable/spinner_border"
                android:spinnerMode="dropdown"
                android:nextFocusForward="@+id/sp1"/>

- Spinner_border.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!--<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="0.5dip"
        android:color="#ffffff" />

    <corners android:radius="80dp" />

    <solid android:color="#ffffff" />-->

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

        <item>

            <layer-list>

                <item>
                    <shape>
                        <gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />

                        <!--<stroke android:width="1dp" android:color="#d9811e" />-->

                        <corners android:radius="60dp" />




                        <padding android:bottom="0dp" android:left="3dp" android:right="3dp" android:top="1dp"
                            />
                    </shape>
                </item>

                <item>

                    <bitmap android:gravity="center|right" android:src="@drawable/selector"/>

                </item>


            </layer-list>

        </item>

    </selector>

<!--
</shape>
-->

- 试试这个