我需要更改微调器弹出窗口的颜色。 这是我到目前为止所尝试的: java代码:
ArrayAdapter<Integer> adapter_year = new ArrayAdapter<Integer>(this, R.drawable.custom_spinner_holidays, year);
adapter_year.setDropDownViewResource(R.layout.customize_spinner);
custom_spinner_holidays.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="@drawable/custom_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@android:color/white" />
customize_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/spinnertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0193DE"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</LinearLayout>
但它不起作用。单击微调器时出现错误。
最佳答案
你让事情变得复杂了!只需将其添加到您的主微调器 xml
android:popupBackground="#yourcolor"
并将您的 java 代码更改为:
adapter_year.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
关于android - 更改 Spinner 弹出窗口的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29625509/