【问题标题】:Change background color of Spinner popup更改 Spinner 弹出窗口的背景颜色
【发布时间】:2019-05-11 00:04:21
【问题描述】:

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

但它不起作用。单击微调器时出现错误。

【问题讨论】:

标签: android android-spinner


【解决方案1】:

你让事情变得复杂了!只需将其添加到您的主微调器 xml

android:popupBackground="#yourcolor"

并将您的 java 代码更改为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-04
    • 2011-04-25
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    相关资源
    最近更新 更多