我希望我的Spinner
有一个黑色渐变背景,左侧是白色文本,右侧是选择器图标(一个向下的白色三角形)。从我的看法来看,有两种方法可以实现这个效果:
If I set the background to an xml drawable resource I can make my
Spinner
look perfect, but then I need to somehow add the white triangle on the right, which I don't know how to go about:<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <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> </selector>
I create a 9-patch image which includes the triangle and then use xml to round the corners and add a stroke to the image. I have had a go at this but was unable to make it work:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/spinnerblack" > <stroke android:width="1dp" android:color="#ffffff" /> <corners android:radius="3dp" /> <padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" /> </item> </selector>
有人能告诉我如何实现方法1,或者在方法2中我做错了什么吗?我不想在我的9-patch图像中添加描边和圆角,因为我认为效果不太好。另外,我更喜欢方法1而不是方法2。非常感谢任何帮助。