【问题标题】:Material button renders icon as a white block材质按钮将图标呈现为白色块
【发布时间】:2020-01-16 02:56:18
【问题描述】:

我正在尝试使用具有材料主题的 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>

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

那么我怎样才能让按钮图标在材质主题中正确显示呢?

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    默认情况下,app:icon 按照MaterialButton documentation 着色为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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 2020-02-06
      • 2019-03-23
      • 2018-11-20
      • 2019-10-13
      • 2019-01-13
      相关资源
      最近更新 更多