public static void changeSize(int[] radio_buttons, int[] drawables, AppCompatActivity activity,int radio_button) {
if(radio_button!=0){
//这里radio_buttons是要设置的单选按钮,drawables是左边图片组,radio_button是单选按钮
for (int i=0;i<radio_buttons.length;i++){
RadioButton radioButton= (RadioButton) activity.findViewById(radio_buttons[i]);
Drawable thing_sign = activity.getResources().getDrawable(drawables[i]);
thing_sign.setBounds(0, 0, 50, 50);
Drawable radio_button_sign=activity.getResources().getDrawable(radio_button);
radio_button_sign.setBounds(0,0,50,50);
radioButton.setCompoundDrawables(thing_sign, null, radio_button_sign, null);
}
}else{
for (int i=0;i<radio_buttons.length;i++){
RadioButton radioButton= (RadioButton) activity.findViewById(radio_buttons[i]);
Drawable thing_sign = activity.getResources().getDrawable(drawables[i]);
thing_sign.setBounds(0, 0, 50, 50);
radioButton.setCompoundDrawables(null, thing_sign, null, null);
}
}
}
}
附上radio_button的代码,供参考
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/radio_checked"/> <item android:state_checked="false" android:drawable="@drawable/nothing"/> </selector>