-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[MaterialButton] Added methods to apply horizontal insets #1790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -432,4 +432,43 @@ public int getInsetTop() { | |||||||||||||
return insetTop; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
public void setInsetLeft(@Dimension int newInsetLeft) { | ||||||||||||||
setHorizontalInsets(newInsetLeft, insetRight); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public int getInsetLeft() { | ||||||||||||||
return insetLeft; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public void setInsetRight(@Dimension int newInsetRight) { | ||||||||||||||
setHorizontalInsets(insetLeft, newInsetRight); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void setHorizontalInsets(@Dimension int newInsetLeft, @Dimension int newInsetRight) { | ||||||||||||||
// Store padding before setting background, since background overwrites padding values | ||||||||||||||
int paddingStart = ViewCompat.getPaddingStart(materialButton); | ||||||||||||||
int paddingTop = materialButton.getPaddingTop(); | ||||||||||||||
int paddingEnd = ViewCompat.getPaddingEnd(materialButton); | ||||||||||||||
int paddingBottom = materialButton.getPaddingBottom(); | ||||||||||||||
int oldInsetLeft = insetLeft; | ||||||||||||||
int oldInsetRight = insetRight; | ||||||||||||||
insetLeft = newInsetLeft; | ||||||||||||||
insetRight = newInsetRight; | ||||||||||||||
if (!backgroundOverwritten) { | ||||||||||||||
updateBackground(); | ||||||||||||||
} | ||||||||||||||
// Set the stored padding values | ||||||||||||||
ViewCompat.setPaddingRelative( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're using If we want to support setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hunterstich In the current code in the material-components-android/lib/java/com/google/android/material/button/MaterialButtonHelper.java Lines 128 to 133 in 5e3ccdc
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good catch I agree, it would be nice to correct/avoid the mix of paddingStart|End and left|right. Using In the future (or now if you want...), we can add in support for |
||||||||||||||
materialButton, | ||||||||||||||
paddingStart + newInsetLeft - oldInsetLeft, | ||||||||||||||
paddingTop , | ||||||||||||||
paddingEnd + newInsetRight - oldInsetRight, | ||||||||||||||
paddingBottom); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public int getInsetRight() { | ||||||||||||||
return insetRight; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about merging this method with
setVerticalInsets
into something likesetInsets(int, int, int, int)
orupdateInsets(int, int, int, int)
? They're almost exactly the same, it might be nice to consolidate logic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will merge the 2 methods.