This code helps you to customize the spinner in ANDROID.
For that you have to create an XML file inside your layout folder as shown below and name it spinner.xml.
You can give all properties that are available for TextView inside this which is going to be then applied for your spinner.
<xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textSize="14sp" android:typeface="serif" android:textStyle="bold|italic" android:textColor="@drawable/yellow" > TextView>
Now I will show you how to add it to a spinner.
ArrayAdapter my_Adapter = new ArrayAdapter(this, R.layout.spinner,my_array); My_spinner.setAdapter(my_Adapter);
“my_array” is an array that populates the spinner and “My_spinner” is the spinner.
Please leave your valuable comments if this post was useful…..
thank you for this post it provided me enough information to get started with custom spinners!
As an addition to your tutorial I found the posting at http://app-solut.com/2011/03/using-custom-layouts-for-spinner-or-listview-entries-in-android/ quite good because it’s covering the topic of how to implement a custom adapter for the spinner. Together with your tutorial I was able to create a fine design for my spinner 🙂
Very nice tutorial…
Pingback: Issue with text color on Spinner in Android App : Android Community - For Application Development
please provide the complete code.First in the xml there is no layout used.
secondly how to specify the id of textview to the adapter?
check this code.