Skip to content

Commit 6b74255

Browse files
committed
修正 Shape 控件在没有设置背景相关属性的情况下仍会覆盖原有的 View 背景问题
1 parent 96d2855 commit 6b74255

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

library/src/main/java/com/hjq/shape/builder/ShapeDrawableBuilder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ public ShapeDrawableBuilder setLineGravity(int gravity) {
673673
}
674674

675675
public Drawable buildBackgroundDrawable() {
676+
Drawable viewBackground = mView.getBackground();
677+
676678
boolean hasSolidColorState = mSolidPressedColor != null || mSolidCheckedColor != null ||
677679
mSolidDisabledColor != null || mSolidFocusedColor != null || mSolidSelectedColor != null;
678680

@@ -681,13 +683,13 @@ public Drawable buildBackgroundDrawable() {
681683

682684
if (!isSolidGradientColorsEnable() && !isStrokeGradientColorsEnable() &&
683685
mSolidColor == NO_COLOR && !hasSolidColorState && mStrokeColor == NO_COLOR && !hasStrokeColorState) {
684-
// 啥都没有设置,直接 return
685-
return null;
686+
// 如果什么属性都没有设置,直接返回原先 View 的背景
687+
// Github issue 地址:https://github.com/getActivity/ShapeView/issues/104
688+
return viewBackground;
686689
}
687690

688691
ShapeDrawable defaultDrawable;
689692

690-
Drawable viewBackground = mView.getBackground();
691693
if (viewBackground instanceof ExtendStateListDrawable) {
692694
defaultDrawable = convertShapeDrawable(((ExtendStateListDrawable) viewBackground).getDefaultDrawable());
693695
} else {

0 commit comments

Comments
 (0)