Three kinds of methods
1. Use XML file for definition Res/drawable/radio.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<!--not selected->
<item
Android:state_checked= "false"
android:drawable= "@drawable/tabswitcher_long"/>
<!--selected->
<item
Android:state_checked= "true"
android:drawable= "@drawable/tabswitcher_short"/>
</selector>
Using in Layout files
Copy Code code as follows:
<radiogroup
...
>
<radiobutton
...
android:button= "@null"
android:background= "@drawable/radio"
/>
</RadioGroup>
ndroid:button= "@null" removes dots in front of RadioButton
android:background= "@drawable/radio" using the defined style
2. Define in Java code
Copy Code code as follows:
@Override
public boolean ontouchevent (Motionevent event) {
if (event.getactionmasked () = = Motionevent.action_down) {
This.setbackgroundresource (COM.WXG.TAB.R.DRAWABLE.MAIN_BG);
}else if (event.getactionmasked () = = Motionevent.action_down) {
This.setbackgroundresource (Com.wxg.tab.r.drawable.hui);
}
Return Super.ontouchevent (event);
}
Remove the dot adiobutton.setbuttondrawable (Android) in front of the RadioButton. R.color.transparent);
3. Using XML file Definitions, using Radiobutton.setbackgroundresource (r.drawable.radio) in Java code;