I have a MaterialButton
constrained on every side and want to fit a vector icon to those constraints so that it expands or contracts based on the button constraints.
These are the basic attributes:
<com.google.android.material.button.MaterialButton
android:layout_width="0dp"
android:layout_height="0dp"
app:icon="@drawable/icon_name"
app:layout_constraintBottom_toTopOf="view1"
app:layout_constraintEnd_toStartOf="view2"
app:layout_constraintStart_toEndOf="view3"
app:layout_constraintTop_toBottomOf="view4" />
I have tried the following:
These are static dimensions based on screen size, so they don't scale.
<com.google.android.material.button.MaterialButton
android:scaleX="3F"
android:scaleY="3F" />
This displays the image in its original size.
<com.google.android.material.button.MaterialButton
app:iconSize="0dp" />
- I cannot use
android:foreground
because I am supporting versions lower than API 23. - I cannot place an image in
android:background
because it breaksMaterialButton
's functionality, as stated in the official documents. - I don't know the purpose of the
android:drawable...
options. There's no way to resize those in xml and they don't have a drawableCenter option.
MaterialButton
class. It's written specifically in a way which enforces you to abide by the design rules. – Cheetah