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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ allprojects {
}
}

apply plugin: 'android-reporting'
//apply plugin: 'android-reporting'
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public class SegmentedGroup extends RadioGroup {
private int mMarginDp;
private Resources resources;
private int mTintColor;
private int mTextColor = Color.CYAN;
private int mCheckedTextColor = Color.WHITE;
private LayoutSelector mLayoutSelector;
private Float mCornerRadius;
private boolean mDrawCheckedDrawable = true;

public SegmentedGroup(Context context) {
super(context);
Expand Down Expand Up @@ -54,6 +56,10 @@ private void initAttrs(AttributeSet attrs) {
R.styleable.SegmentedGroup_tint_color,
getResources().getColor(R.color.radio_button_selected_color));

mTextColor = typedArray.getColor(
R.styleable.SegmentedGroup_text_color,
getResources().getColor(android.R.color.holo_blue_bright));

mCheckedTextColor = typedArray.getColor(
R.styleable.SegmentedGroup_checked_text_color,
getResources().getColor(android.R.color.white));
Expand All @@ -80,6 +86,12 @@ protected void onFinishInflate() {
updateBackground();
}

public void setTextColor(int textColor)
{
mTextColor = textColor;
updateBackground();
}

public void setTintColor(int tintColor) {
mTintColor = tintColor;
updateBackground();
Expand All @@ -91,6 +103,11 @@ public void setTintColor(int tintColor, int checkedTextColor) {
updateBackground();
}

public void setDrawCheckedDrawable(boolean b) {
mDrawCheckedDrawable = b;
updateBackground();
}

public void updateBackground() {
int count = super.getChildCount();
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -120,13 +137,14 @@ private void updateBackground(View view) {
{android.R.attr.state_pressed},
{-android.R.attr.state_pressed, -android.R.attr.state_checked},
{-android.R.attr.state_pressed, android.R.attr.state_checked}},
new int[]{Color.GRAY, mTintColor, mCheckedTextColor});
new int[]{Color.GRAY, mTextColor, mCheckedTextColor});
((Button) view).setTextColor(colorStateList);

//Redraw with tint color
Drawable checkedDrawable = resources.getDrawable(checked).mutate();
Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
((GradientDrawable) checkedDrawable).setColor(mTintColor);
if(mDrawCheckedDrawable)
((GradientDrawable) checkedDrawable).setColor(mTintColor);
((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor);
((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor);
//Set proper radius
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/drawable/button_text_color.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#DDd4d4d4" />
<item android:state_pressed="false" android:state_checked="false" android:color="@color/radio_button_selected_color" />
<item android:state_pressed="false" android:state_checked="false" android:color="@color/radio_button_text_color" />
<item android:state_pressed="false" android:state_checked="true" android:color="#fff2f2f2" />
</selector>
7 changes: 6 additions & 1 deletion library/src/main/res/drawable/radio_checked.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
android:shape="rectangle"
android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="@color/radio_button_selected_color" />
<!--<solid android:color="@color/radio_button_selected_color" />-->
<gradient
android:type="linear"
android:startColor="#ff4dd512"
android:endColor="#ff2a9b02"
android:angle="270"/>
<stroke
android:width="@dimen/radio_button_stroke_border"
android:color="@color/radio_button_selected_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 @@ -4,6 +4,7 @@
<attr name="corner_radius" format="dimension" />
<attr name="border_width" format="dimension" />
<attr name="tint_color" format="color" />
<attr name="text_color" format="color" />
<attr name="checked_text_color" format="color" />
</declare-styleable>

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
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="radio_button_selected_color">#ff33b5e5</color>
<color name="radio_button_text_color">#ff33b5e5</color>
<color name="radio_button_unselected_color">@android:color/transparent</color>
</resources>