如何去除 Material 按钮中图标的色调?

How to remove tint on icon in Material Button?

我想要 "Sign in with Google" 带有白色背景和彩色图标的按钮,但是当我使用这个 Google 图标时总是有颜色。

  <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"/>

如何让图标不着色?

我已经找到了解决方案,我只是更改了 iconTintMode 和 iconTint 颜色

  <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"/>

我愿意接受更好的解决方案

使用这个并退出色调图标显示真实颜色

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

例子

<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

您还可以使用白色作为 iconTint,并使用 multiply 作为 iconTintMode 用于彩色图标。

 app:iconTint="@color/white"
 app:iconTintMode="multiply"

None 这些答案对我有用。但经过大量试验后,我发现这确实有效。

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

看来关键是android:background="#0000"。不知道为什么 @null 不起作用,但这就是最终让那种愚蠢的颜色消失的原因。

button.iconTint = ColorStateList.valueOf(Color.TRANSPARENT)