第一步:java代码中不再选择默认布局,自定义spinner和其item布局
年级spinner
// arrayadapter = ArrayAdapter.createFromResource(this, R.array.grade_list, R.layout.spinner_text);
// spinner = (Spinner) findViewById(R.id.grade_list);
// arrayadapter.setDropDownViewResource(R.layout.spinner_item);
// spinner.setAdapter(arrayadapter);
// tvSpinnerSelectIcon = (TextView) findViewById(R.id.spinner_select_icon);
// tvSpinnerSelectIcon.setTypeface(font);
// spinner.setOnItemSelectedListener(onGradeClick);
第二步:注意: android:id="@android:id/text1" ,id必须和默认布局id相同
spinner_text.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textColor="@color/bottombar_textcolor"
android:textAlignment="inherit"/>
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="42dp"
android:gravity="center_vertical|center_horizontal"
android:textSize="16sp"
android:textColor="@color/bottombar_textcolor"
android:background="@drawable/spinner_item_bgchange">
</TextView>