1, prepare two pictures, and do 9.png
650) this.width=650; "Name=" image_operate_50101341392844221 "title=" Android <wbr> custom <wbr>spinner < wbr> (background, font color) "alt=" Android <wbr> custom <wbr>spinner <wbr> (background, font color) "src=" http://s1.sinaimg.cn/ middle/3e333c4axc3fd5b1bb340&690 "/>
2. Define spinner_selector.xml in drawable
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_pressed= "true"
android:drawable= "@drawable/spinner_press"/>< effect!--Press
<item android:state_pressed= "false"
android:drawable= "@drawable/spinner"/><!--default Effect--
</selector>
3. defined in style
<!--spinner--
<style name= "spinner_style" >
<item name= "Android:background" >@drawable/spinner_selector</item>
<item name= "Android:paddingleft" >5dip</item>
</style>
4. Call
<spinner
Android:id= "@+id/field_item_spinner_content"
style= "@style/spinner_style"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:animationcache= "true"
Android:drawselectorontop= "true"/>
5. Define simple_spinner_item.xml in Layout
<?xml version= "1.0" encoding= "Utf-8"?>
<checkedtextview xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@android: Id/text1"
android:paddingleft= "5dip"
android:paddingright= "5dip"
Android:gravity= "Center_vertical"
Android:textcolor= "#808080"
Android:singleline= "true"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
/>
6. Java code
arrayadapter<string> adapter = new Arrayadapter<string> (mcontext, r.layout.simple_spinner_item );
String level[] = getresources (). Getstringarray (R.array.affair_level);//resource file
for (int i = 0; i < level.length; i++) {
Adapter.add (Level[i]);
}
Adapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);
Spinner.setadapter (adapter);
650) this.width=650; "Name=" image_operate_19871341393403270 "width=" 461 "height=" "title=" Android <wbr> Custom <wbr>spinner <wbr> (background, font color) "alt=" Android <wbr> custom <wbr>spinner <wbr> (background, font color) "src=" http://s2.sinaimg.cn/middle/3e333c4axc3fd61ad0ab1&690 "/>
650) this.width=650; "Name=" image_operate_56181341393403695 "title=" Android <wbr> custom <wbr>spinner < wbr> (background, font color) "alt=" Android <wbr> custom <wbr>spinner <wbr> (background, font color) "src=" http://s11.sinaimg.cn/ middle/3e333c4axc3fd644b385a&690 "/>
This article is from "Little book" blog, please make sure to keep this source http://8988940.blog.51cto.com/8978940/1579376
Android Custom Spinner (background, font color)