Android customizes the RadioButton style in three ways

  • 2020-05-09 19:17:30
  • OfStack

The three methods
1. Define res/drawable/ radio.xml using the XML file
 
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!--  uncheck -> 
<item 
android:state_checked="false" 
android:drawable="@drawable/tabswitcher_long" /> 
<!-- The selected -> 
<item 
android:state_checked="true" 
android:drawable="@drawable/tabswitcher_short" /> 
</selector> 

Used in layout files
 
<RadioGroup 
... 
> 
<RadioButton 
... 
android:button="@null" 
android:background="@drawable/radio" 
/> 
</RadioGroup> 

ndroid:button=" @null "remove the dot in front of RadioButton
android:background=" @drawable /radio" using the defined style
2. Defined in JAVA code
 
@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 front RadioButton dot adioButton. setButtonDrawable (android. R. color. transparent);
3. radioButton.setBackgroundResource (R.drawable.radio) in JAVA; call

Related articles: