In this Android tip, I am going give you an example using layer-list drawable object to customize a spinner to look as shown in the image below.
<Spinner
android:id= "@+id/spinner_outlet_type"
android:layout_width="200dp"
android:layout_height="60dp"
android:padding="15dp"
android:background="@drawable/spinner_bg_style"
android:popupBackground="#cccccc"
android:entries= "@array/array_outlettypes"
/>
In the res/drawable directory, you create an xml file called spinner_bg_style.xml that defines a layer-list. In the layer-list, there are two items: a shape object and a bitmap. The shape object defines the background of the spinner. The bitmap item represents the dropdown arrow of the spinner. The source of the bitmap is an image called arrow.png in the res/drawable directory. The bitmap draws on top of the shape. <?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="#cccccc" android:startColor="#d8d8d8" android:type="linear" />
<padding android:bottom="0dp" android:left="0dp" android:right="3dp" android:top="0dp" />
</shape>
</item>
<item>
<bitmap android:gravity="center|right" android:src="@drawable/arrow" />
</item>
</layer-list></item>
</selector>
|
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.