Android Development-Set the RadioButton click Effect

Source: Internet
Author: User

Using the bottom menu bar in Android development requires the RadioButton component.

In the actual application process, you need to click on the button, in order to let users know whether to click on this button, you can set the click, the button's color or background changes.

The code in this section of layout is:

1 <RadioButton2 android:id="@+id/radio_button0"3 android:layout_height="Fill_parent"4 android:layout_margintop="2.0dip"5 android:drawabletop="@drawable/icon"6 android:tag="Radio_button0"7 android:textcolor="@color/color_radiobutton"
            android:background= "@color/radio_group_selector"8 Android:Checked="True"//set to checked, the displayed effect is the selected font color9 android:text="Button No. 1th"/>Ten <RadioButtonAndroid:id="@+id/radio_button1"android:layout_height="Fill_parent"android:layout_margintop= "2.0dip" 14 android:tag= "radio_button1 "15 android:drawabletop= " @drawable/icon"
android:background= "@color/radio_group_sele ctor " 16 android:textcolor=" @color/color_radiobutton "17 Android:text= " button 2nd # "/>

You can see android:textcolor="@color/color_radiobutton" in RadioButton

android:background="@color/radio_group_selector"

This is going to correspond to two files.

Under the Res folder, create a name called Color folder, and then create an XML file in the Color folder Color_radiobutton to set the selected click Color change for changing the font

That is, the file directory is: Res/color/color_radiobutton

The code for this file is

1<?xml version="1.0"encoding="Utf-8"?>2<selector xmlns:android="http://schemas.android.com/apk/res/android">3   4   5<item android:state_checked="true"Android:color="@color/green"/>6<!--not selected--7<itemandroid:state_checked="false" Android:color="@color/white"/>8   9   Ten</selector>

Under the Res folder, create a name called Color folder, and then create an XML file in the Color folder Radio_group_selector to set the selected click Color change for changing the font

That is, the file directory is: Res/color/radio_group_selector

1<?xml version="1.0"encoding="Utf-8"?>2<selector xmlns:android="http://schemas.android.com/apk/res/android">3<item android:state_checked="true"android:drawable="@color/green"></item>4<item android:state_checked="false"android:drawable="@color/black"></item>5</selector>

You can see that when the color of the click Is green, the color is green without being clicked, the text is white and the background is black.

And, of course, set the color in Res/values/color.xml.

1<?xml version="1.0"encoding="Utf-8"?>2<resources>3<color name="Black">#000000</color>4<color name=" White"> #FFFFFF </color>5<color name="Green"> #00FF00 </color>6     7</resources>

It's done.

Android Development-Set the RadioButton click Effect

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.