Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion demo/src/main/res/layout/fragment_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
segmentedgroup:sc_corner_radius="10dp"
segmentedgroup:sc_tint_color="#FFEB3B"
segmentedgroup:sc_unchecked_tint_color="#ff0000"
segmentedgroup:sc_checked_text_color="#7C4DFF">
segmentedgroup:sc_checked_text_color="#7C4DFF"
segmentedgroup:sc_unchecked_text_color="#000000">

<RadioButton
android:id="@+id/button21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SegmentedGroup extends RadioGroup {
private int mTintColor;
private int mUnCheckedTintColor;
private int mCheckedTextColor = Color.WHITE;
private int mUnCheckedTextColor;
private LayoutSelector mLayoutSelector;
private Float mCornerRadius;
private OnCheckedChangeListener mCheckedChangeListener;
Expand All @@ -40,6 +41,7 @@ public SegmentedGroup(Context context) {
resources = getResources();
mTintColor = resources.getColor(R.color.radio_button_selected_color);
mUnCheckedTintColor = resources.getColor(R.color.radio_button_unselected_color);
mUnCheckedTextColor = resources.getColor(R.color.radio_button_unselected_text_color);
mMarginDp = (int) getResources().getDimension(R.dimen.radio_button_stroke_border);
mCornerRadius = getResources().getDimension(R.dimen.radio_button_conner_radius);
mLayoutSelector = new LayoutSelector(mCornerRadius);
Expand All @@ -50,6 +52,7 @@ public SegmentedGroup(Context context, AttributeSet attrs) {
resources = getResources();
mTintColor = resources.getColor(R.color.radio_button_selected_color);
mUnCheckedTintColor = resources.getColor(R.color.radio_button_unselected_color);
mUnCheckedTextColor = resources.getColor(R.color.radio_button_unselected_text_color);
mMarginDp = (int) getResources().getDimension(R.dimen.radio_button_stroke_border);
mCornerRadius = getResources().getDimension(R.dimen.radio_button_conner_radius);
initAttrs(attrs);
Expand Down Expand Up @@ -83,6 +86,10 @@ private void initAttrs(AttributeSet attrs) {
mUnCheckedTintColor = typedArray.getColor(
R.styleable.SegmentedGroup_sc_unchecked_tint_color,
getResources().getColor(R.color.radio_button_unselected_color));

mUnCheckedTextColor = typedArray.getColor(
R.styleable.SegmentedGroup_sc_unchecked_text_color,
getResources().getColor(R.color.radio_button_unselected_text_color));
} finally {
typedArray.recycle();
}
Expand Down Expand Up @@ -111,6 +118,11 @@ public void setUnCheckedTintColor(int unCheckedTintColor, int unCheckedTextColor
updateBackground();
}

public void setUnCheckedTextColor(int unCheckedTextColor) {
mUnCheckedTextColor = unCheckedTextColor;
updateBackground();
}

public void updateBackground() {
mDrawableMap = new HashMap<>();
int count = super.getChildCount();
Expand Down Expand Up @@ -140,7 +152,7 @@ private void updateBackground(View view) {
ColorStateList colorStateList = new ColorStateList(new int[][]{
{-android.R.attr.state_checked},
{android.R.attr.state_checked}},
new int[]{mTintColor, mCheckedTextColor});
new int[]{mUnCheckedTextColor, mCheckedTextColor});
((Button) view).setTextColor(colorStateList);

//Redraw with tint color
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<attr name="sc_tint_color" format="color" />
<attr name="sc_checked_text_color" format="color" />
<attr name="sc_unchecked_tint_color" format="color"/>
<attr name="sc_unchecked_text_color" format="color"/>
</declare-styleable>

<declare-styleable name="AwesomeRadioButton">
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<color name="radio_button_selected_color">#ff33b5e5</color>
<color name="radio_button_unselected_color">#e0e0e0</color>
<color name="radio_button_unselected_text_color">#ff33b5e5</color>
</resources>