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?
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?
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.