Android中自定义控件SegmentedGroup

GitHub:https://github.com/Kaopiz/android-segmented-control

一 、添加依赖

implementation 'info.hoang8f:android-segmented:1.0.6'

二、布局中使用

<info.hoang8f.android.segmented.SegmentedGroup
        app:sc_border_width="2dp"
        app:sc_checked_text_color="#f00"
        app:sc_corner_radius="5dp"
        app:sc_tint_color="#fff"
        android:background="@color/colorAccent"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="40dp">

        <RadioButton
            android:id="@+id/button1"
            android:textSize="18sp"
            android:button="@null"
            style="@style/RadioButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="CSDN"/>

        <RadioButton
            android:id="@+id/button2"
            android:textSize="18sp"
            android:button="@null"
            style="@style/RadioButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Android"/>

    </info.hoang8f.android.segmented.SegmentedGroup>

 三、其他设置

1. 当按方法检查按钮时,您也可以更改色调颜色和标题颜色setTintColor

mSg.setTintColor(R.color.radio_button_selected_color);
mSg.setTintColor(Color.parseColor("#FFD0FF3C"), Color.parseColor("#FF7B07B2"));

2. 如果你不指定border_width和/或corner_radius,将使用默认值(border_width为1dp,corner_radius为5dp)。

3. 其他的逻辑方法就按照RadioGroup使用即可。

猜你喜欢

转载自blog.csdn.net/qq_40441190/article/details/84975510