1、准备两张图片,并做好9.png
2、在drawable中定义
spinner_selector.xml
<?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" /><!--按下时效果-->
<item android:state_pressed="false"
android:drawable="@drawable/spinner" /><!--默认效果-->
</selector>
3、style中定义
<!-- spinner -->
<style name="
spinner_style">
<item name="android:background">
@drawable/spinner_selector</item>
<item name="android:paddingLeft">5dip</item>
</style>
4、调用
<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、在layout中定义
simple_spinner_item.xml
<?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代码
ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
R.layout.simple_spinner_item);
String level[] = getResources().getStringArray(R.array.affair_level);//资源文件
for (int i = 0; i < level.length; i++) {
adapter.add(level[i]);
}
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);