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

 

5 Comments

  1. Lavagi April 13, 2011 at 7:37 am

    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 🙂

     
  2. Romain February 3, 2013 at 4:55 pm

    Very nice tutorial…

     
  3. Pingback: Issue with text color on Spinner in Android App : Android Community - For Application Development

  4. George December 20, 2013 at 8:56 am

    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?

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.