Android User-Defined radiobutton style to achieve what you want, androidradiobutton

Source: Internet
Author: User

Android User-Defined radiobutton style to achieve what you want, androidradiobutton

:


The style customization for radiobutton is nothing more than the style. There is a background in the style to set the radiobutton background button to set the radiobutton small box. When it is null, it is not a box.

The first custom style:

 <style name="CustomRadioBtn">        <item name="android:button">@drawable/mycustome_radio_selctor</item>    </style>

Code for mycustome_radio_selctor xml:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/enable_on_pressed" android:state_checked="true" android:state_enabled="true" android:state_pressed="true"/>    <item android:drawable="@drawable/enable_off_pressed" android:state_checked="false" android:state_enabled="true" android:state_pressed="true"/>    <item android:drawable="@drawable/enable_on" android:state_checked="true" android:state_enabled="true"/>    <item android:drawable="@drawable/enable_off" android:state_checked="false" android:state_enabled="true"/>    <item android:drawable="@drawable/disabled_on" android:state_checked="true" android:state_enabled="false"/>    <item android:drawable="@drawable/disabled_off" android:state_checked="false" android:state_enabled="false"/></selector>


The second custom style:

<style name="CustomRadioBtn2">        <item name="android:gravity">center</item>        <item name="android:background">@drawable/rb_nobtn_selector</item>        <item name="android:button">@null</item>    </style>

Rb_nobtn_selector xml:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/rb_pressed_bg" android:state_checked="true"></item>    <item android:drawable="@drawable/rb_normal_bg" android:state_checked="false"></item></selector>


You only need to pay attention to the state_checked status.

In this way, the effect is achieved. It is better to use the. 9 image, and set the gravity to center.



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.