material
material copied to clipboard
RadioGroup support
Hi,
nice library!
For RadioGroup support :+1: #49 #76
+1 ...
+1 ...
+1
+1
a solution is to extend AppCompatRadioButton:
public class RadioButton extends AppCompatRadioButton {
private RadioButtonDrawable drawable;
public RadioButton( Context context ) {
super(context);
init(context, null, 0, R.style.Material_Drawable_RadioButton);
}
public RadioButton( Context context, AttributeSet attrs ) {
super(context, attrs);
init(context, attrs, 0, R.style.Material_Drawable_RadioButton);
}
public RadioButton( Context context, AttributeSet attrs, int defStyleAttr ) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, R.style.Material_Drawable_RadioButton);
}
public RadioButton( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes ) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr, defStyleRes);
}
private void init( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes ) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = new RadioButtonDrawable.Builder(context, attrs, defStyleAttr, defStyleRes).build();
drawable.setInEditMode(isInEditMode());
drawable.setAnimEnable(false);
setButtonDrawable(drawable);
drawable.setAnimEnable(true);
}
}
@Override
public void toggle() {
if (!isChecked()) {
super.toggle();
}
}
public void setCheckedImmediately( boolean checked ) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable.setAnimEnable(false);
setChecked(checked);
drawable.setAnimEnable(true);
}
else {
setChecked(checked);
}
}
}