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

标签 android android-spinner

我需要更改微调器弹出窗口的颜色。 这是我到目前为止所尝试的: 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/

相关文章:

android - Toast 不会从屏幕上消失

java - 递归排列字符串无法完成超过 9 个字符 - 抛出 OutOfMemoryError

android - 如何刷新 View 页面中的 fragment ?

android - 无法在 android 中为微调器设置 OnItemClickListener

Android Holo 主题不包含多行微调器下拉项

java - 如何获取微调器中所选项目的值?

java - 从手机上传 PDF 到 firebase

java - 如何在 android 谷歌地图版本 2 中的 2 个地理点之间画线?

android - 将 entryValues 与 Spinner 元素一起使用

android - 如何将微调器中的第一个值(默认值)设置为空