material-components-android: [MaterialButton] drawableStart doesn't work, both in preview nor in device
Description: [MaterialButton] android:drawableStart doesn’t work, both in preview nor in device. It ended up the same whether you’re using xml drawable or bitmap.
Expected behavior: Drawable expected to be drawn at the start of the MaterialButton.
Resulted behavior:
From top to bottom:
drawableEnd - drawableStart - drawableTop - drawableBottom
Source code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:drawableEnd="@drawable/ic_android_black_24dp"/>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:drawableStart="@drawable/ic_android_black_24dp"/>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:drawableTop="@drawable/ic_android_black_24dp"/>
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:drawableBottom="@drawable/ic_android_black_24dp"/>
</LinearLayout>
Android API version: API 22 and above; might have also happened on earlier APIs.
Material Library version: 1.1.0
Device: Android Studio Emulator
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 17 (4 by maintainers)
Hey there!
Instead of using
drawableBottom|Top|Left|...useMaterialButton’s attributesapp:iconandapp:iconGravity.Like:
The above is from our catalog demo app here: https://github.com/material-components/material-components-android/blob/master/catalog/java/io/material/catalog/button/res/layout/cat_buttons_fragment.xml#L140-L141
I’m going to go ahead and close this but if this isn’t what you were asking or doesn’t solve the issue, feel free to reopen!
I think Material Button should support drawableStart, End, etc. though.
Because there’s a case where we need multiple icons on a button:
I just merged this PR which adds support for adding an icon above a button’s text - https://github.com/material-components/material-components-android/pull/1129
That should be synced out soon if that helps
@marklwembe it does somewhat relate, as you are suffering from auto inflation.
https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/theme/MaterialComponentsViewInflater.java
This is why the issue is especially frustrating; just by changing the theme, we need to be aware of this and retroactively patch existing buttons.
Ensure to add
iconTintusing app:iconapp:icon="@drawable/ic_rubbish" app:iconGravity="textStart" app:iconTint="@android:color/holo_red_light"