Go: Android custom RadioButton Style

Source: Internet
Author: User

http://gundumw100.iteye.com/blog/1146527
How does the effect of the above 3-choice 1 work? Write in code?
In fact, there is a more simple way to forget the RadioButton have any characteristics?
I used RadioButton to achieve the above effect, in fact, very simple.
First define a background, named Radio.xml, and note that the background must be an XML-styled picture:
XML code
<?XML version= "1.0" encoding= "Utf-8"?>   <selectorxmlns:android= "Http://schemas.android.com/apk/res/android">       <Itemandroid:state_checked= "false"android:drawable= "@drawable/tabswitcher_long" />       <Itemandroid:state_checked= "true"android:drawable= "@drawable/tabswitcher_short" />   </selector>   


Here we can only care about the state_checked state. So it's very simple to configure.
The next step is to refer to this image in the layout file:
Layout file

 

<Radiogroup android:gravity= "Center"android:orientation= "Horizontal"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content" > <RadioButton Android:id= "@+id/btn_0"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Latest Information"android:textsize= "17.0SP"Android:textcolor= "@android: Color/black"android:gravity= "Center"Android:layout_weight= "1"android:checked= "true"Android:button= "@null"Android:background= "@drawable/radio"/> <RadioButton Android:id= "@+id/btn_1"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Online Expert"android:textsize= "17.0SP"Android:textcolor= "@android: Color/black"android:gravity= "Center"Android:layout_weight= "1"Android:button= "@null"Android:background= "@drawable/radio"/> <RadioButton Android:id= "@+id/btn_2"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Reservation Service"android:textsize= "17.0SP"Android:textcolor= "@android: Color/black"android:gravity= "Center"Android:layout_weight= "1"Android:button= "@null"Android:background= "@drawable/radio"/> </RadioGroup>


Note android:button= "@null" is all set to NULL, and android:background= "@drawable/radio" is set to the picture you just created. So it's done.
You don't have to write a single line of code!

Look at the effect of the vertical:


What if there are icons on the side?


Also very simple, as long as in each RadioButton add android:drawableleft= "@drawable/tubiao_0" on it.
Also to set the distance between the icon and the text?
There is a way setcompounddrawablepadding (PAD) can set the distance between the icon and the text, the corresponding property is android:drawablepadding.

With this trick can be achieved similar to the N 1 effect, see below:



Application:
http://www.iteye.com/topic/1116261#2256664

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.