如何更改操作栏中的微调器文本颜色

How to change spinner text color in the actionbar

在我的项目中,我在操作栏中扩展了这个自定义布局:

Link to image

但我想要白色的微调器文本。 我在网上看到了很多关于这个的话题,但我还不能解决这个问题。 我该如何解决这个问题?如何通过将微调器设置为白色来更改微调器的文本颜色?

编辑: xml spinner 的代码是这样的:

<Spinner
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:textColor="#ffffff"
    android:id="@+id/spinner"></Spinner>

很简单,我试了很多东西都没有..

像这样创建布局文件:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/spinner_ref_id"
    android:layout_width="match_parent"
    android:padding="20dp"
    android:textColor="#fff"
    android:textSize="20sp"
    android:text="Hello"
    android:layout_height="wrap_content">

</TextView>

假设您使用 ArrayAdapter 作为 Spinner 适配器。

希望对您有所帮助!!!

在你的 activity 你应该有这样的东西: (基本上你正在获取 Spinner 并将其设置为适配器。此适配器负责填充它)

Spinner spinner = (Spinner) findViewById(R.id.your_spinner_id);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.your_selected_spinner_item, myArrayList<String));

adapter.setDropDownViewResource(R.layout.your_dropdown_item);
spinner.setAdapter(adapter);

您可以拥有以下 XML:(将它们放在 res/layout)

your_selected_spinner_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myLayoutID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="20sp"/>

还有 your_dropdown_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myDropdownLayoutID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="20sp"/>