0

I want to change spinner text color (who is actually white) , to black .

I inserted string arrays in the spinner directly from string.xml file :

<resources>
....
...
<string name="vil_prompt">Choisir une ville</string>

<string-array name="vil_arrays">
    <item><FONT COLOR="#006600">Nouakchott Nord -Dar Naim </FONT></item>
    <item>Nouakchott Est - Tevrag Zeina</item>
    <item>Nouakchott Sud - Araffat</item>
    <item>Nouadhibou</item>
    <item>Rosso</item>
    <item>Adel baghrou</item>
    <item>Boughé</item>
    <item>Kiffa</item>
    <item>Zouerate</item>
    <item>kaédi</item>
    <item>Boû Gadoûm</item>
    <item>Boutilimit</item>
    <item>Atar</item>
    <item>Bareina</item>
    <item>Hamoud</item>
    <item>Mal</item>
</string-array>
</resources> 

I find many different solution , but in majority of case , it was because they populated their spinner via the java code . i didn't initialized the spinner in the java file actually .

i found a solution who suggested to apply <FONT COLOR>...</FONT> to the string array but nothing changed (i applied the code to the first item as you can see)

Pic

i have two spinner , you can't actually see them because of the text color and background.

<Spinner
        android:id="@+id/spinner4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/spinner3"
        android:layout_marginTop="17dp"
        android:entries="@array/vil_arrays"
        android:prompt="@string/vil_prompt"
        android:textColor="#808080"
        />

How to fix that ? thanks

1 Answer 1

1

In your res/layout folder make a custom_spinner_item.xml file like:

<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    android:textColor="@android:color/black"
    style="?android:attr/spinnerDropDownItemStyle">
</TextView>

In your java file populate your Spinner like:

ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(YourActivity.this, R.array.vil_arrays, R.layout.custom_spinner_item);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.