-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Closed
Description
Recently I found out Button have attribute iconGravity and it does nothing, in onMeasure() it saves new position in iconLeft variable. but it never used anywhere
or am I missing anything??
implementation 'com.google.android.material:material:1.0.0-beta01'
Code Sample From Project:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (this.icon != null && this.iconGravity == 2) {
Paint textPaint = this.getPaint();
int textWidth = (int)textPaint.measureText(this.getText().toString());
int localIconSize = this.iconSize == 0 ? this.icon.getIntrinsicWidth() : this.iconSize;
int newIconLeft = (this.getWidth() - textWidth - ViewCompat.getPaddingEnd(this) - localIconSize - this.iconPadding - ViewCompat.getPaddingStart(this)) / 2;
if (this.isLayoutRTL()) {
newIconLeft = -newIconLeft;
}
if (this.iconLeft != newIconLeft) {
this.iconLeft = newIconLeft;
this.updateIcon();
}
}
}
private void updateIcon() {
if (this.icon != null) {
this.icon = this.icon.mutate();
DrawableCompat.setTintList(this.icon, this.iconTint);
if (this.iconTintMode != null) {
DrawableCompat.setTintMode(this.icon, this.iconTintMode);
}
int width = this.iconSize != 0 ? this.iconSize : this.icon.getIntrinsicWidth();
int height = this.iconSize != 0 ? this.iconSize : this.icon.getIntrinsicHeight();
this.icon.setBounds(0, 0, width, height);
}
TextViewCompat.setCompoundDrawablesRelative(this, this.icon, (Drawable)null, (Drawable)null, (Drawable)null);
}
zsmb13
Metadata
Metadata
Assignees
Labels
No labels