How to remove tint on icon in Material Button?
Asked Answered
H

5

33

I want to have "Sign in with Google" button with white background and colored icon, but when I use this Google icon always gets tinted.

  <android.support.design.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button.Icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sign in with Google"
    app:icon="@drawable/ic_google_colored"/>

How do I make icon not tinted?

Hygiene answered 18/10, 2018 at 17:52 Comment(0)
H
57

I already found a solution, I just changed iconTintMode and iconTint color

  <android.support.design.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button.Icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Sign in with Google"
    app:icon="@drawable/ic_google_colored"
    app:iconTint="@android:color/transparent"
    app:iconTintMode="add"/>

I am open to better solutions

Hygiene answered 18/10, 2018 at 17:59 Comment(0)
T
48

Use this and quit tint icon to show real color

  app:icon="@drawable/ic_google"
  app:iconTint="@null"

Example

<Button
  android:id="@+id/idGoogle"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:icon="@drawable/ic_google"
  app:iconTint="@null"/>

icon with real color shows black background

Tiernan answered 13/2, 2019 at 19:57 Comment(1)
Accepted answer doesn't work on OutlinedButton. This solution works on OutlinedButton as well 👍Radiancy
A
2

You can also use white color as iconTint and use multiply as iconTintMode for colorful icons.

 app:iconTint="@color/white"
 app:iconTintMode="multiply"
Anora answered 14/12, 2020 at 7:55 Comment(0)
F
0

None of these answers worked for me. But after experimenting a lot I found this did the trick.

<Button
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:scaleType="fitCenter"
    android:background="#0000"
    android:foreground="@android:drawable/ic_menu_camera"
    />

It seems that the key is android:background="#0000". Don't know why @null didn't work, but this is what finally got that stupid color to go away.

Fritts answered 5/6, 2021 at 14:43 Comment(0)
R
-1
button.iconTint = ColorStateList.valueOf(Color.TRANSPARENT)
Rivalee answered 25/10, 2021 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.