更改Spinner弹出窗口的背景颜色

10

我需要改变旋转加载图标弹出框的颜色。 以下是我到目前为止尝试过的代码: Java 代码:

ArrayAdapter<Integer> adapter_year = new ArrayAdapter<Integer>(this, R.drawable.custom_spinner_holidays, year);
adapter_year.setDropDownViewResource(R.layout.customize_spinner);

自定义旋转器假日.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" />

自定义_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>

但是它不起作用。当我点击旋转器时,出现错误。


https://dev59.com/7IHba4cB1Zd3GeqPVL3N - Harin
希望这个有效...https://dev59.com/OWcs5IYBdhLWcg3wwmnA - Badhrinath Canessane
1个回答

21
您让事情变得复杂了!只需将此添加到您的主旋转器xml中即可。

android:popupBackground="#yourcolor"

并将您的Java代码更改为:

adapter_year.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接