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

时间:2020-01-16 02:56:18

标签: android material-design

我正在尝试使用具有实质性主题的google按钮创建登录,但是该图标显示为白色块。我正在使用由Google here提供的登录资产。

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

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

styles.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light">
       ...
</style>

enter image description here

但是,如果我使用带有普通按钮的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"
/>

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
         ...
</style>

enter image description here

那么如何使按钮图标正确显示在实质主题中?

1 个答案:

答案 0 :(得分:3)

默认情况下,根据MaterialButton documentationapp: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" />