ios UISegmentedControl 适用于 android
android-segmented-control ========================= Android-Segmented 是一个基于 RadioGroup 和 RadioButton widget 的 Android 自定义视图。此实现灵感来自 iOS 的 Segmented Controls。
依赖项 { 编译 'info.hoang8f:android-segmented:1.0.6' }
将以下文件(或合并)复制到对应的文件/文件夹:
在 xml 中定义如下,并确保 RadioButton 的样式为 @style/RadioButton
<attr name="sc_corner_radius" format="dimension" />
<attr name="sc_border_width" format="dimension" />
<attr name="sc_tint_color" format="color" />
<attr name="sc_checked_text_color" format="color" />示例代码:
…您还可以通过 setTintColor 方法更改按钮选中时的颜色和标题颜色。
以下是示例代码:
SegmentedGroup segmented2 = (SegmentedGroup) rootView.findViewById(R.id.segmented2);
segmented2.setTintColor(Color.DKGRAY);
SegmentedGroup segmented3 = (SegmentedGroup) rootView.findViewById(R.id.segmented3);
segmented3.setTintColor(Color.parseColor("#FFD0FF3C"), Color.parseColor("#FF7B07B2"));
SegmentedGroup segmented4 = (SegmentedGroup) rootView.findViewById(R.id.segmented4);
segmented4.setTintColor(getResources().getColor(R.color.radio_button_selected_color));如果您未指定 border_width 和/或 corner_radius,则会使用默认值(bo 为 1dp)
暂无开放 Issues,或尚未同步最近议题。