這裏是通過XML解決方案:
微調的樣子:
<Spinner
android:id="@+id/settingsSleepingTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/spinner_main_button"
android:popupBackground="@color/colorPrimary"
android:textColor="@android:color/white"
android:textSize="20sp"/>
在創建微調器設置setDropDownViewResource自定義佈局:
adapter.setDropDownViewResource(R.layout.spinner_item);
和SPINN er_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="wrap_content"
android:background="@drawable/spinner"
android:textColor="#ffffff"
android:textSize="20sp" />
最後,我們設置@繪製/微調這樣的:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimaryLight" android:state_hovered="true" />
<item android:drawable="@color/colorPrimaryLight" android:state_selected="true" />
</selector>
希望我的回答將是有益的!
你需要實現它的getDropDownView()方法,做到這一點,如果不能夠再在這裏發表您的代碼 – Vickyexpert
在旋轉的適配器的onclick應用,併爲特定項目的新的背景顏色。 –
@Vickyexpert:你能給我一個想法,我怎樣才能使用getDropDownView()方法來實現這一點。這將是一個很大的幫助。先進的感謝很多。 –