Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Commit 8e6adf3

Browse files
committed
Fix for group background color.
1 parent db32929 commit 8e6adf3

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

library/src/main/java/co/ceryle/radiorealbutton/library/RadioRealButton.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ else if (hasPaddingBottom || hasPaddingTop || hasPaddingLeft || hasPaddingRight)
192192
container.setBackgroundColor(backgroundColor);
193193
}
194194

195+
public void setButtonBackgroundColor(int backgroundColor){
196+
this.backgroundColor = backgroundColor;
197+
if (hasRipple)
198+
RippleHelper.setRipple(container, backgroundColor, rippleColor);
199+
}
200+
195201
private boolean hasRipple = false;
196202
private int backgroundColor, rippleColor;
197203

@@ -347,10 +353,6 @@ public int getButtonBackgroundColor() {
347353
return buttonBackgroundColor;
348354
}
349355

350-
public void setButtonBackgroundColor(int buttonBackgroundColor) {
351-
this.buttonBackgroundColor = buttonBackgroundColor;
352-
}
353-
354356
public int getButtonRippleColor() {
355357
return buttonRippleColor;
356358
}

library/src/main/java/co/ceryle/radiorealbutton/library/RadioRealButtonGroup.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,6 @@ private void setContainerAttrs() {
218218
}
219219
}
220220

221-
public void setGroupBackgroundColor() {
222-
if (hasGroupBackgroundColor)
223-
container.setBackgroundColor(groupBackgroundColor);
224-
}
225-
226221
private RelativeLayout.LayoutParams borderParams;
227222

228223
private void setBorderAttrs() {
@@ -243,15 +238,15 @@ private void setBorderAttrs() {
243238
private int borderSize, borderColor, dividerColor, bottomLineColor, selectorColor, animateImages, animateTexts,
244239
animateImagesDuration, animateTextsDuration, animateSelector, animateSelectorDuration, animateImagesExit,
245240
animateImagesExitDuration, animateTextsExit, animateTextsExitDuration, lastPosition, buttonPadding,
246-
buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, groupBackgroundColor;
241+
buttonPaddingLeft, buttonPaddingRight, buttonPaddingTop, buttonPaddingBottom, groupBackgroundColor, dividerBackgroundColor;
247242

248243
private float bottomLineSize, dividerSize, dividerRadius, dividerPadding, shadowElevation, selectorSize,
249244
shadowMargin, shadowMarginTop, shadowMarginBottom, shadowMarginLeft, shadowMarginRight, radius,
250245
bottomLineRadius, selectorRadius, animateImagesScale, animateTextsScale;
251246

252247
private boolean shadow, bottomLineBringToFront, selectorBringToFront, selectorAboveOfBottomLine, selectorTop, selectorBottom,
253248
hasPadding, hasPaddingLeft, hasPaddingRight, hasPaddingTop, hasPaddingBottom, hasGroupBackgroundColor, hasAnimation,
254-
clickable, enabled;
249+
clickable, enabled, hasDividerBackgroundColor;
255250

256251
private void getAttributes(AttributeSet attrs) {
257252
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.RadioRealButtonGroup);
@@ -273,6 +268,8 @@ private void getAttributes(AttributeSet attrs) {
273268
dividerRadius = typedArray.getDimension(R.styleable.RadioRealButtonGroup_rrbg_dividerRadius, 0);
274269
dividerPadding = typedArray.getDimension(R.styleable.RadioRealButtonGroup_rrbg_dividerPadding, 30);
275270
dividerColor = typedArray.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerColor, Color.GRAY);
271+
dividerBackgroundColor = typedArray.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor, Color.WHITE);
272+
hasDividerBackgroundColor = typedArray.hasValue(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor);
276273

277274
shadow = typedArray.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_shadow, false);
278275
shadowElevation = typedArray.getDimension(R.styleable.RadioRealButtonGroup_rrbg_shadowElevation, 0);
@@ -353,6 +350,10 @@ public void onClick(View v) {
353350
}
354351
});
355352

353+
if (hasGroupBackgroundColor) {
354+
button.setButtonBackgroundColor(groupBackgroundColor);
355+
}
356+
356357
setButtonPadding(button);
357358

358359
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
@@ -858,6 +859,11 @@ public void deselect() {
858859
lastPosition = -1;
859860
}
860861

862+
863+
public void setGroupBackgroundColor() {
864+
container.setBackgroundColor(hasDividerBackgroundColor ? dividerBackgroundColor : groupBackgroundColor);
865+
}
866+
861867
private void setRippleState(boolean state) {
862868
for (RadioRealButton b : buttons) {
863869
b.setRipple(state);

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<attr name="rrbg_dividerPadding" format="dimension"/>
5757
<attr name="rrbg_dividerColor" format="color"/>
5858
<attr name="rrbg_dividerRadius" format="dimension"/>
59+
<attr name="rrbg_dividerBackgroundColor" format="color"/>
5960

6061
<attr name="rrbg_shadow" format="boolean"/>
6162
<attr name="rrbg_shadowElevation" format="dimension"/>

sample/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
android:layout_height="wrap_content"
2929
app:rrbg_animateTexts_enter="overshoot"
3030
app:rrbg_animateTexts_enterDuration="500"
31-
app:rrbg_backgroundColor="@color/white"
3231
app:rrbg_bottomLineColor="@color/grey_600"
3332
app:rrbg_bottomLineSize="2dp"
3433
app:rrbg_dividerColor="@color/grey_500"
@@ -85,18 +84,18 @@
8584
app:rrbg_animateImages_exitDuration="500"
8685
app:rrbg_animateTexts_enter="overshoot"
8786
app:rrbg_animateTexts_enterDuration="500"
88-
app:rrbg_backgroundColor="#FFF"
87+
app:rrbg_backgroundColor="@color/red_500"
8988
app:rrbg_bottomLineBringToFront="true"
9089
app:rrbg_bottomLineColor="@color/blue_300"
9190
app:rrbg_bottomLineRadius="2dp"
9291
app:rrbg_bottomLineSize="0dp"
9392
app:rrbg_buttonsPaddingBottom="8dp"
9493
app:rrbg_buttonsPaddingTop="8dp"
95-
app:rrbg_position="0"
9694
app:rrbg_dividerColor="@color/black"
9795
app:rrbg_dividerPadding="10dp"
9896
app:rrbg_dividerRadius="2dp"
9997
app:rrbg_dividerSize="1dp"
98+
app:rrbg_position="0"
10099
app:rrbg_radius="2dp"
101100
app:rrbg_selectorAboveOfBottomLine="false"
102101
app:rrbg_selectorBringToFront="true"
@@ -158,9 +157,9 @@
158157
app:rrbg_borderSize="1dp"
159158
app:rrbg_bottomLineSize="0dp"
160159
app:rrbg_dividerColor="@color/black"
161-
app:rrbg_position="0"
162160
app:rrbg_dividerPadding="0dp"
163161
app:rrbg_dividerSize="1dp"
162+
app:rrbg_position="0"
164163
app:rrbg_radius="28dp"
165164
app:rrbg_selectorColor="@color/yellow_600"
166165
app:rrbg_selectorSize="6dp"
@@ -252,8 +251,8 @@
252251
app:rrbg_dividerPadding="10dp"
253252
app:rrbg_dividerRadius="0dp"
254253
app:rrbg_dividerSize="1dp"
255-
app:rrbg_radius="2dp"
256254
app:rrbg_position="0"
255+
app:rrbg_radius="2dp"
257256
app:rrbg_selectorAboveOfBottomLine="true"
258257
app:rrbg_selectorBringToFront="true"
259258
app:rrbg_selectorColor="@color/green_400"
@@ -316,11 +315,11 @@
316315
app:rrbg_animateImages_exit="overshoot"
317316
app:rrbg_animateImages_exitDuration="1500"
318317
app:rrbg_animateSelector="bounce"
319-
app:rrbg_position="0"
320318
app:rrbg_bottomLineColor="@color/white"
321319
app:rrbg_buttonsPadding="8dp"
322320
app:rrbg_dividerColor="@color/white"
323321
app:rrbg_dividerSize="0dp"
322+
app:rrbg_position="0"
324323
app:rrbg_radius="4dp"
325324
app:rrbg_selectorAboveOfBottomLine="true"
326325
app:rrbg_selectorColor="@color/white"

0 commit comments

Comments
 (0)