我已经创建了我使用的一个微调的背景下绘制。我想,但现在这样的背景下内部的箭头图像。我试图像机器人:drawableRight =arrowimage,但这似乎并没有显示任何东西。有谁知道我可以包括图像在我的自定义背景的微调?
I have created a background drawable that I use for a spinner. I would like to now but an arrow image inside this background. I have tried things like android:drawableRight="arrowimage", but this does not seem to show anything. Does anyone know how I can include an image in my custom background for a spinner?
与任何名称,例如spinner_bg.xml创建在绘制文件夹中的XML,并添加以下行
Create an XML in drawable folder with any name for example spinner_bg.xml and add the following lines
<?xml version="1.0" encoding="utf-8"?>
<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="#504a4b" />
<corners android:radius="5dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape></item>
<item ><bitmap android:gravity="bottom|right" android:src="@drawable/spinner_ab_default_holo_dark_am" /> // you can use any other image here, instead of default_holo_dark_am
</item>
</layer-list></item>
</selector>
添加以下行到你的styles.xml这是内部价值观的文件夹
Add the following lines to your styles.xml which is inside values folder
<style name="spinner_style" >
<item name="android:background">@drawable/spinner_bg</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
现在添加这种风格到您的微调为
Now add this style to your spinner as
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/spinner_style"
android:popupBackground="#cccccc" />