Recently in the project has a lot of drop-down box, in order to realize the convenience of using the Android spinner, but the spinner style does not meet the requirements, and then learn the custom spinner. Here's the whole step:
1. Get the picture ready.
Defined in 2.style
<!--spinner-->
<style name= "Spinner_style" >
<item name= "Android:background" >@ drawable/spinner</item>
<item name= "Android:paddingleft" >5dip</item>
3. Call
<spinner
android:id= "@+id/field_item_spinner_content"
style= "@style/spinner_style"
android: Layout_width= "Fill_parent"
android:layout_height= "Wrap_content"/>
4. 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"/>
5.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);
Effect Chart: