Custom Spinner with rounded corners, stroked edge and a selector icon

前端 未结 1 1472
难免孤独
难免孤独 2021-02-04 14:50

I want my Spinner to have a black gradient background with white text on the left and a selector icon on the right (a white downwards pointing triangle). As I see i

相关标签:
1条回答
  • 2021-02-04 15:22

    I've done something similar to method 1 in my app. Basically you need to combine your selector with a layer-list:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <layer-list>
                <item>
                    <shape>
                        <gradient
                            android:startColor="#343434"
                            android:endColor="#171717"
                            android:angle="270" />
                        <stroke
                            android:width="1dp"
                            android:color="#ffffff" />
                        <corners
                            android:radius="4dp" />
                        <padding
                            android:left="3dp"
                            android:top="3dp"
                            android:right="3dp"
                            android:bottom="3dp" />
                    </shape>
                </item>
                <item
                    android:top="12dp"
                    android:right="15dp">
                    <bitmap android:src="@drawable/arrow_bitmap"
                            android:gravity="top|right" />
                </item>
            </layer-list>
        </item>
    </selector>
    

    In my xml I also added a third layer containing a <shape> that is invisible (i.e. its alpha is set to 0) but adds padding.

    0 讨论(0)
提交回复
热议问题