材质按钮将图标呈现为白色块

use*_*158 1 android material-design

我正在尝试创建一个带有材质主题的 Google 登录按钮,但该图标显示为白色块。我在这里使用谷歌提供的登录资源。

如果我使用带有材质主题的材质按钮

按钮 XML

<com.google.android.material.button.MaterialButton
       android:id="@+id/btn_material"
       style="@style/Widget.MaterialComponents.Button.Icon"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:text="Sign In with Google"
       app:icon="@mipmap/ic_launcher_round" />
Run Code Online (Sandbox Code Playgroud)

样式.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light">
       ...
</style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但如果我使用带有普通按钮的 appcompat 主题,它就可以正常工作

按钮 XML

<Button
     android:id="@+id/btn_appcompat"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:drawableStart="@mipmap/ic_launcher_round"
     android:text="Sign In with Google"
/>
Run Code Online (Sandbox Code Playgroud)

样式.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
         ...
</style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

那么如何让按钮图标在 Material 主题中正确显示呢?

ian*_*ake 5

默认情况下,根据MaterialButton 文档app:icon着色app:iconTint

app:iconTint="@null"您可以通过添加到按钮来禁用此行为:

<com.google.android.material.button.MaterialButton
   android:id="@+id/btn_material"
   style="@style/Widget.MaterialComponents.Button.Icon"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="Sign In with Google"
   app:icon="@mipmap/ic_launcher_round"
   app:iconTint="@null" />
Run Code Online (Sandbox Code Playgroud)