@@ -675,9 +675,8 @@ public ShapeDrawableBuilder setLineGravity(int gravity) {
675675 return this ;
676676 }
677677
678+ @ Nullable
678679 public Drawable buildBackgroundDrawable () {
679- Drawable viewBackground = mView .getBackground ();
680-
681680 boolean hasSolidColorState = mSolidPressedColor != null || mSolidCheckedColor != null ||
682681 mSolidDisabledColor != null || mSolidFocusedColor != null || mSolidSelectedColor != null ;
683682
@@ -686,13 +685,11 @@ public Drawable buildBackgroundDrawable() {
686685
687686 if (!isSolidGradientColorsEnable () && !isStrokeGradientColorsEnable () &&
688687 mSolidColor == NO_COLOR && !hasSolidColorState && mStrokeColor == NO_COLOR && !hasStrokeColorState ) {
689- // 如果什么属性都没有设置,直接返回原先 View 的背景
690- // Github issue 地址:https://github.com/getActivity/ShapeView/issues/104
691- return viewBackground ;
688+ return null ;
692689 }
693690
694691 ShapeDrawable defaultDrawable ;
695-
692+ Drawable viewBackground = mView . getBackground ();
696693 if (viewBackground instanceof ExtendStateListDrawable ) {
697694 defaultDrawable = convertShapeDrawable (((ExtendStateListDrawable ) viewBackground ).getDefaultDrawable ());
698695 } else {
@@ -814,7 +811,29 @@ public void intoBackground() {
814811 // https://developer.android.com/guide/topics/graphics/hardware-accel?hl=zh-cn
815812 mView .setLayerType (View .LAYER_TYPE_SOFTWARE , null );
816813 }
817- mView .setBackground (drawable );
814+ if (drawable != null ) {
815+ mView .setBackground (drawable );
816+ }
817+ }
818+
819+ public void clearBackground () {
820+ mSolidColor = NO_COLOR ;
821+ mSolidGradientColors = null ;
822+ mSolidPressedColor = null ;
823+ mSolidCheckedColor = null ;
824+ mSolidDisabledColor = null ;
825+ mSolidFocusedColor = null ;
826+ mSolidSelectedColor = null ;
827+
828+ mStrokeColor = NO_COLOR ;
829+ mStrokeGradientColors = null ;
830+ mStrokePressedColor = null ;
831+ mStrokeCheckedColor = null ;
832+ mStrokeDisabledColor = null ;
833+ mStrokeFocusedColor = null ;
834+ mStrokeSelectedColor = null ;
835+
836+ mView .setBackground (null );
818837 }
819838
820839 /**
0 commit comments