Android Custom Spinner Style

Source: Internet
Author: User

First, add a spinner control to the XML

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context = "${packagename}.${activityclass}" > <spinner android:id= "@+id/sp" android:layout_width= "Match_pare NT "android:layout_height=" Wrap_content "/></relativelayout>

Then add a spinner item to the XML, which sets the effect of each column, the name is called: Spitem.xml

<?xml version= "1.0" encoding= "Utf-8"? ><textview xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @+id/text1 "style="? Android:attr/spinnerdropdownitemstyle "Android:layout_width=" Match_paren  T "android:layout_height=" 40SP "android:textsize=" 30sp "android:background=" #FFFFFF "android:singleline=" true " />

Finally, load the spinner in the code

import android.app.activity;import android.os.bundle;import  android.widget.ArrayAdapter;import android.widget.Spinner;public class MainActivity  extends activity {spinner spinner; @Overrideprotected  void oncreate (bundle  savedinstancestate)  {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Spinner= ( Spinner) Findviewbyid (R.ID.SP); String data[]=new string[]{"A", "B", "C"};//declares a arrayadaper, which is used to load spinner data arrayadapter<string> Adapter=new arrayadapter<string> (this, android. R.layout.simple_spinner_item, data);//Load the item's layout style Adapter.setdropdownviewresource (r.layout.spitem);// Finally let spinner load Adapterspinner.setadapter (adapter);}} 

Operating effect:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/DC/wKioL1S_ITGgvbcYAAB2AFewdtQ507.jpg "title=" Qq20150121114258.png "alt=" Wkiol1s_itggvbcyaab2afewdtq507.jpg "/>

Android Custom Spinner Style

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.