美文网首页
自定义RadioButton

自定义RadioButton

作者: 一个冬季 | 来源:发表于2019-03-15 11:32 被阅读0次
效果图.png
xml
 <RadioGroup
            android:id="@+id/rg_creation_security_group"
            android:layout_marginLeft="@dimen/dp_27"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RadioButton
                android:id="@+id/rb_creation_security_group_jingdian"
                android:text="经典"
                android:textSize="@dimen/sp_12"
                android:button="@drawable/select_circle_radiubutton"
                android:textColor="@color/dark_222222"
                android:gravity="center"
                android:checked="true"
                android:paddingLeft="@dimen/dp_5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <RadioButton
                android:layout_marginLeft="@dimen/dp_10"
                android:id="@+id/rb_creation_security_group_zhuanyou"
                android:text="专有"
                android:paddingLeft="@dimen/dp_5"
                android:button="@drawable/select_circle_radiubutton"
                android:gravity="center"
                android:textColor="@color/dark_222222"
                android:textSize="@dimen/sp_12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </RadioGroup>
select_circle_radiubutton
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/icon_circle_checked"></item>
    <item android:state_checked="false" android:drawable="@drawable/icon_circle_unchecked"></item>
</selector>

文字跟图片的距离,要通过padding来设置

android
  radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (jingDianRadioButton.getId() == checkedId){
                    ToastUtils.getInstance().showMessage("经典");
                }else {
                    ToastUtils.getInstance().showMessage("专有");
                }
            }
        });

相关文章

网友评论

      本文标题:自定义RadioButton

      本文链接:https://www.haomeiwen.com/subject/wmllmqtx.html