@@ -32,23 +32,25 @@ public class OmegaCenterIconButton extends AppCompatButton {
3232 private Rect textBoundsRect ;
3333 @ ColorInt
3434 private int tintColor = Color .TRANSPARENT ;
35+ private int mLeftPadding ;
36+ private int mRightPadding ;
3537
3638 public OmegaCenterIconButton (Context context ) {
3739 super (context );
38- initDrawableTint (context , null );
40+ init (context , null );
3941 }
4042
4143 public OmegaCenterIconButton (Context context , AttributeSet attrs ) {
4244 super (context , attrs );
43- initDrawableTint (context , attrs );
45+ init (context , attrs );
4446 }
4547
4648 public OmegaCenterIconButton (Context context , AttributeSet attrs , int defStyleAttr ) {
4749 super (context , attrs , defStyleAttr );
48- initDrawableTint (context , attrs );
50+ init (context , attrs );
4951 }
5052
51- private void initDrawableTint (Context context , AttributeSet attrs ) {
53+ private void init (Context context , AttributeSet attrs ) {
5254 if (attrs != null ) {
5355 TypedArray typedArray = context .obtainStyledAttributes (attrs , R .styleable .OmegaCenterIconButton );
5456 tintColor = typedArray .getColor (R .styleable .OmegaCenterIconButton_drawableTint , Color .TRANSPARENT );
@@ -59,6 +61,8 @@ private void initDrawableTint(Context context, AttributeSet attrs) {
5961 updateTint ();
6062 typedArray .recycle ();
6163 }
64+ mLeftPadding = getPaddingLeft ();
65+ mRightPadding = getPaddingRight ();
6266 }
6367
6468 private void updateTint () {
@@ -107,6 +111,14 @@ private void updatePadding() {
107111 updatePadding (getMeasuredWidth ());
108112 }
109113
114+ @ Override
115+ public void setPadding (int left , int top , int right , int bottom ) {
116+ super .setPadding (left , top , right , bottom );
117+ mLeftPadding = left ;
118+ mRightPadding = right ;
119+ updatePadding ();
120+ }
121+
110122 private void updatePadding (int width ) {
111123 if (width == 0 ) return ;
112124
@@ -129,7 +141,8 @@ private void updatePadding(int width) {
129141 paddingSize = (width - rightDrawable .getIntrinsicWidth () - iconPadding * 2 - textWidth ) / 2 ;
130142 }
131143
132- setPadding (paddingSize , getPaddingTop (), paddingSize , getPaddingBottom ());
144+
145+ super .setPadding (Math .max (mLeftPadding , paddingSize ), getPaddingTop (), Math .max (paddingSize , mRightPadding ), getPaddingBottom ());
133146 }
134147
135148 private int getTextWidth () {
0 commit comments