как изменить текст в элементе представления Android Spinner - PullRequest
0 голосов
/ 14 марта 2020

многие другие ответы говорят мне, что android: textColor это тот, который делает трюк. Однако независимо от того, какой атрибут я изменяю в моих стилях, приложение все равно показывает черный текст по умолчанию.
На самом деле, я даже не вижу атрибута с именем textColor или тому подобное в редакторе макета - вкладка attribs.

Ответы [ 2 ]

0 голосов
/ 14 марта 2020
**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); 
0 голосов
/ 14 марта 2020

См. Здесь: Spinner с пользовательским шрифтом и цветом текста

Здесь вы можете создать пользовательский файл 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. 

А затем установите адаптер.

...