@@ -267,7 +267,7 @@ private void setContent() {
267
267
268
268
LayoutParams layoutParamsText ;
269
269
LayoutParams layoutParamsImage ;
270
- if (drawablePosition >= 0 || drawablePosition <= 3 || drawableNormal != null ) {
270
+ if (drawablePosition >= 0 || drawablePosition <= 3 && drawableNormal != null ) {
271
271
int width = (drawablePosition % 2 == 0 ) ? 0 : ViewGroup .LayoutParams .MATCH_PARENT ;
272
272
int height = (drawablePosition % 2 == 0 ) ? ViewGroup .LayoutParams .MATCH_PARENT : 0 ;
273
273
layoutParamsText = new LinearLayout .LayoutParams (width , height );
@@ -279,8 +279,10 @@ private void setContent() {
279
279
textView .setLayoutParams (layoutParamsText );
280
280
imageContainer .setLayoutParams (layoutParamsImage );
281
281
282
- if (drawablePressed == null ) drawablePressed = drawableNormal ;
283
- if (drawableDisabled == null ) drawablePressed = drawableNormal ;
282
+ if (drawablePressed == null )
283
+ drawablePressed = drawableNormal .getConstantState ().newDrawable ().mutate ();
284
+ if (drawableDisabled == null )
285
+ drawablePressed = drawableNormal .getConstantState ().newDrawable ().mutate ();
284
286
285
287
StateListDrawable listDrawable = new StateListDrawable ();
286
288
listDrawable .addState (new int []{android .R .attr .state_pressed }, drawablePressed );
@@ -320,7 +322,7 @@ private void setContent() {
320
322
}
321
323
322
324
} else {
323
- layoutParamsText = new LinearLayout .LayoutParams (getLayoutParams (). width , getLayoutParams (). height );
325
+ layoutParamsText = new LinearLayout .LayoutParams (ViewGroup . LayoutParams . MATCH_PARENT , ViewGroup . LayoutParams . MATCH_PARENT );
324
326
textView .setLayoutParams (layoutParamsText );
325
327
if (text != null ) {
326
328
textView .setGravity (Gravity .CENTER );
@@ -420,7 +422,6 @@ private void imageColorStateListToIntegers(ColorStateList colorStateList) {
420
422
drawableColorDisabled = globalColor ;
421
423
}
422
424
423
-
424
425
private void updateText () {
425
426
textColorArray = new int []{textColorPressed , textColorNormal , textColorDisabled };
426
427
textColorList = new ColorStateList (stateArray , textColorArray );
@@ -500,7 +501,6 @@ private Drawable changeDrawableColor(Bitmap bitmap, int color) {
500
501
return new BitmapDrawable (b );
501
502
}
502
503
503
-
504
504
/**
505
505
* Set shape backgroundColorNormal.
506
506
*
@@ -513,7 +513,6 @@ public void setShapeBackground(int shapeType, int shapeRadius) {
513
513
setShapeBackground ();
514
514
}
515
515
516
-
517
516
public void setPrimaryColor (int color ) {
518
517
519
518
updatePrimaryColor (color );
@@ -548,7 +547,6 @@ public void setMainColors(int primaryColor, int secondaryColor) {
548
547
* pressed - for pressed state,
549
548
* (empty) - for disabled state.
550
549
*/
551
-
552
550
public void setBackgroundColorStateList (ColorStateList colorStateList ) {
553
551
554
552
backgroundColorStateListToIntegers (colorStateList );
@@ -583,7 +581,6 @@ public void setBackgroundColorNormal(int backgroundColorNormal) {
583
581
* @param color Integer frame color
584
582
* @param size Float frame size
585
583
*/
586
-
587
584
public void setFrame (int color , float size ) {
588
585
frameSize = size ;
589
586
frameColorNormal = color ;
@@ -752,6 +749,13 @@ public void setImage(int position, Drawable drawableNormal, Drawable drawablePre
752
749
this .imageWeight = weight ;
753
750
this .imagePaddingArray = padding ;
754
751
752
+ if (padding != null )
753
+ imageContainer .setPadding (padding [LEFT ], padding [TOP ], padding [RIGHT ], padding [BOTTOM ]);
754
+ else
755
+ imageContainer .setPadding (0 , 0 , 0 , 0 );
756
+ if (scaleType != null )
757
+ imageContainer .setScaleType (scaleType );
758
+
755
759
setContent ();
756
760
}
757
761
@@ -764,19 +768,7 @@ public void setImage(int position, Drawable drawableNormal, Drawable drawablePre
764
768
* @param padding 4 elements array {CustomButton.LEFT, CustomButton.TOP, CustomButton.RIGHT, CustomButton.BOTTOM}
765
769
*/
766
770
public void setImage (int position , Drawable drawable , ImageView .ScaleType scaleType , int weight , int [] padding ) {
767
- this .drawableNormal = drawable ;
768
- this .drawablePosition = position ;
769
- this .imageWeight = weight ;
770
- this .imagePaddingArray = padding ;
771
-
772
- if (padding != null )
773
- imageContainer .setPadding (padding [LEFT ], padding [TOP ], padding [RIGHT ], padding [BOTTOM ]);
774
- else
775
- imageContainer .setPadding (0 , 0 , 0 , 0 );
776
- if (scaleType != null )
777
- imageContainer .setScaleType (scaleType );
778
-
779
- setContent ();
771
+ setImage (position , drawable , drawable , drawable , scaleType , weight , padding );
780
772
}
781
773
782
774
public void setImageColors (int normal , int pressed , int disabled ) {
@@ -812,7 +804,6 @@ public void setImageDisableColor(int color) {
812
804
setContent ();
813
805
}
814
806
815
-
816
807
/**
817
808
* Set elevation to button. If enabled button is smaller because shadow must have space to show.
818
809
*
@@ -853,7 +844,6 @@ public int getShapeType() {
853
844
return shapeType ;
854
845
}
855
846
856
-
857
847
public boolean isElevationEnabled () {
858
848
return isElevationEnabled ;
859
849
}
0 commit comments