material icon indicating copy to clipboard operation
material copied to clipboard

RadioGroup support

Open fernandodev opened this issue 9 years ago • 5 comments

Hi,

nice library!

For RadioGroup support :+1: #49 #76

fernandodev avatar Jun 18 '15 14:06 fernandodev

+1 ...

rocboronat avatar Jun 29 '15 15:06 rocboronat

+1 ...

ArabAgile avatar Jul 06 '15 09:07 ArabAgile

+1

Eyadoos avatar Mar 15 '16 20:03 Eyadoos

+1

joielechong avatar Mar 21 '16 13:03 joielechong

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);
        }
    }
}

Bapho avatar Jun 07 '16 11:06 Bapho