许多其他答案的确告诉我android:textColor是解决问题的方法。但是,无论我更改样式的什么属性,应用程序仍会显示默认的黑色文本。实际上,我什至在布局编辑器-attribs选项卡中都看不到名为textColor的属性或类似属性。
参见此处:Spinner with custom text font and color
在这里您可以在布局文件夹中创建自定义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.
然后设置适配器。
**I hope my solution would work,**
<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);