如何更改 Android Spinner 视图元素上的文本

how to change the text on an Android Spinner view element

许多其他答案确实告诉我 android:textColor 是解决问题的答案。但是,无论我在样式中更改什么属性,应用程序仍然显示默认的黑色文本。
事实上,我什至在布局编辑器 - 属性选项卡中看不到名为 textColor 或类似属性的属性。

看这里:

在这里您可以在布局文件夹中创建自定义 xml 文件,您可以在其中添加:

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#333333"
android:padding="10dp"
android:textStyle="bold"  /> 

然后在您的代码中这样提及:

    val adapter = ArrayAdapter.createFromResource(this, R.array.array_name, R.layout.custom_spinner) // where array_name consists of the items to show in Spinner
    adapter.setDropDownViewResource(R.layout.custom_spinner) // where custom-spinner is 

mycustom xml file. 

然后设置适配器。

我希望我的解决方案能奏效,

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


And then change your declaration of the spinner to use the R.layout.spinner_item:

ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item);
spinner.setAdapter(adapter);