Search code examples
androidstylesspinnertextcolor

how to change the text on an Android Spinner view element


the many other answers do tell me that android:textColor is the one that does the trick. However no matter what attribute I change in my styles, the app still shows default Black text.
In fact, I cannot even see an attribute called textColor or the likes of it in the layout editor - attribs tab.


Solution

  • See here: Spinner with custom text font and color

    Here you can make a custom xml file in layout folder where you can add this:

    <?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"  /> 
    

    And then in your code mention it like this:

        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. 
    

    And then set the adapter.