When using theme for Activity Theme.MaterialComponents....
if I want to use drawableLeft/Right
etc. with a button they are not shown. But if I use theme Base.Theme.AppCompat
they worked as expected.
Here is Button:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test Button"
android:drawableLeft="@drawable/ic_envelope"/>
And this is how it looks with theme Base.Theme.MaterialComponents
And this is with Base.Theme.AppCompat
How can I make drawableLeft
work with Base.Theme.MaterialComponents
theme?
Just use a MaterialButton
with the app:icon
attribute:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
app:icon="@drawable/ic_add_24px"
../>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
app:icon="@drawable/ic_add_24px"
../>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
app:icon="@drawable/ic_add_24px"
../>
Use the app:iconGravity
to config start|end|textStart|textEnd
.
<com.google.android.material.button.MaterialButton
app:iconGravity="end"
../>