0

I have a spinner that loads data from string-array and I would like to customize it from the XML layout and not from Java code (as I saw in many examples).

Is it possible to change the text color and the spinner style from XML?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sharas
  • 1,985
  • 3
  • 20
  • 43
  • This will be helpful for changing the text color and style https://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color – Ramesh sambu Dec 13 '17 at 16:03
  • Check if this can helps you http://www.broculos.net/2013/09/how-to-change-spinner-text-size-color.html#.WjFQuUqWY2w – sommesh Dec 13 '17 at 16:10

1 Answers1

-1

Yes you can, here is how you add a spinner layout

item_spinner.xml

    <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_margin="@dimen/small_margin"
    android:background="@color/white"
    android:ellipsize="marquee"
    android:paddingLeft="@dimen/margin_small"
    android:singleLine="true"
    android:text="--Select--"
    android:textColor="@color/text_title"
    />

and use in your adapter like this

ArrayAdapter<String> itemsAdapter = 
    new ArrayAdapter<String>(this,R.layout.item_spinner, items);

and you are done. customize but keep the textView id same that is how adapter will set text on it.

vikas kumar
  • 10,447
  • 2
  • 46
  • 52