Customize a spinner style in Android

Source: Internet
Author: User
To customize styles for components such as listview and expandablelistview, define a layout (linnearlayout/reativelayout ..) in the layout directory ..) you can use the header-based labels. However, a problem occurs when customizing the style for the spinner, adapter. setdropdownviewresource (R. layout. myweather_citylist); the tag cannot start with layout. For example, the content in the myweather_citylist.xml file is as follows: <? XML version = "1.0" encoding = "UTF-8"?> <Textview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Id = "@ + ID/weather_cityname_textview" Android: layout_width = "fill_parent" Android: layout_height = "35dip" Android: textcolor = "# ff0000" Android: text = "yaneryaneryaneryaner Android: textsize =" 20dip "Android: textstyle =" bold "style = "? Android: ATTR/spinnerdropdownitemstyle "> </textview>. In addition, the adpter adapter cannot be customized. Otherwise, the effect will not be displayed. Instead, you can directly introduce the defined XML file to setdropdownviewresource. If you change the style, you can only work on textview. This is the current horizontal perception. It is estimated that there are other Replacement Methods O (∩ _ ∩) O ~ The following is a complete small example: --- string. xml <? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "spinner_promat"> select a choose: </string> </resources> ---- each item in the spinner <? XML version = "1.0" encoding = "UTF-8"?> <Textview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: TEXT = "Spinner item"> </textview> ---- test the layout style of the activity. <? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "match_parent" Android: layout_height = "match_parent"> <spinner Android: id = "@ + ID/mspinner_comp" Android: layout_width = "fill_parent" Android: layout_height = "50dip" Android: prompt = "@ string/spinner_promat" <! -- Note that the title of prompt must be defined in string and cannot be written directly here -->/> </linearlayout> --- test activitypublic class mspinnertestactivity extends activity {protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. spinner_layout); Init ();} private void Init () {spinner mspinner = (spinner) findviewbyid (R. id. mspinner_comp); arrayadapter <Object> adapter = new arrayadapter <Object> (this, android. r. layout. simple_spinner_item, new string [] {"yaner", "wife"}); adapter. setdropdownviewresource (R. layout. spinner_item_stypelayout); // you can set a sentence here to setdropdownviewresource mspinner. setadapter (adapter );}}

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.