question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[MaterialButton] drawableStart doesn't work, both in preview nor in device

See original GitHub issue

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: Screenshot_1585826764 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

32reactions
hunterstichcommented, Apr 3, 2020

Hey there!

Instead of using drawableBottom|Top|Left|... use MaterialButton’s attributes app:icon and app:iconGravity.

Like:

      <Button
          style="@style/Widget.MaterialComponents.Button.OutlinedButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:contentDescription="@string/cat_button_icon_btn_text"
          app:icon="@drawable/ic_dialogs_24px"
          app:iconGravity="textStart"
          app:iconPadding="0dp"/>

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!

19reactions
risalfajarcommented, Mar 15, 2021

I think Material Button should support drawableStart, End, etc. though.

Because there’s a case where we need multiple icons on a button: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

drawable start not working with material button - Stack Overflow
I am using material themes, so this will be inflated into a material button drawableStart has no effect at all, however drawableEnd, bottom...
Read more >
MaterialButton - Android Developers
A convenience class for creating a new Material button. This class supplies updated Material styles for the button in the constructor.
Read more >
Want To Add Icon On Button, Drawabletop Is Not Working ...
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 ...
Read more >
TextView drawableTint not working with drawableStart ...
I'm currently developing Android application and I found this issue. Development Env - compileSdkVersion 23 - buildToolsVersion 23.0.1. How to reproduce
Read more >
Different Ways to Fix "Android Studio Does not Show Layout ...
Just try a method if that doesn't work skip to the next method. ... and still not able to see the Layout Preview,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found