Amir
Amir

Reputation: 1815

Material Button icon is not aligned properly when iconPadding is small

Create a MaterialButton with following attributes:

<com.google.android.material.button.MaterialButton
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        app:icon="@drawable/ic_star"
        app:iconGravity="textStart"
        app:iconPadding="0dp" />

When updating the text to a short text, like "123", that does not change the width of the button, the icon does not align properly and may overlap the text. But if the text is long enough, like "123456789", to change the button's width, everything is alright.

MaterialButton iconPadding bug

It is more obvious when iconPadding is set to a small number like zero. In the gif above iconPadding is 2.

Android API version:
API 21, 26, 29

Material Library version:
com.google.android.material:material:1.6.0-alpha02

Am I doing something wrong? or this is a bug.
How can I resolve this issue?

Upvotes: 1

Views: 465

Answers (1)

Amir
Amir

Reputation: 1815

Update:
The issue is fixed (see here), waiting for the next release.


For anyone how has faced the same problem:
I reported this issue in github (here) and it is marked as a bug.
I will update this answer if it is fixed in next versions.

Upvotes: 1

Related Questions