I'm using com.google.android.material.button.MaterialButton as a button :
<com.google.android.material.button.MaterialButton
android:id="@+id/openGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/open_gallery"
android:textAllCaps="true"
android:textColor="@color/dark_pink"
android:textSize="32sp"
android:textStyle="bold"
app:backgroundTint="@null"
app:icon="@drawable/ic_gallery"
app:iconSize="64sp"
app:iconTint="@color/dark_pink"
app:shapeAppearance="@style/CutTopLeftBottomRight"
app:strokeColor="@color/dark_pink"
app:strokeWidth="6dp" />
As you can see, OPEN GALLERY is breaking into two lines instead of staying on a single line. The MaterialButton's width is set to fit the text content, but it doesn't seem to be considering this.
How to fix this issue without using android:layout_width="match_parent"
What I want :


Your text is overflowing to the next line because you just don't have enough space. So the only option it got is either overflow to the next line or get truncated when maxLines is set to 1. It would be helpful if you could also paste the parent of this material button to give more insights.