【问题标题】:issue with setting background drawable in FAB in material 1.1.0在材料 1.1.0 中的 FAB 中设置背景可绘制的问题
【发布时间】:2020-08-08 20:07:25
【问题描述】:

所以,我正在为我的 FAB 设置自定义背景。

 <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/landing_offer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/ic_batch_gold"
    app:backgroundTint="@color/white"
    app:layout_anchor="@id/bar"
    app:maxImageSize="50dp" />

给定的drawable正在FAB上绘制。但它的所有颜色都消失了。它全是黑色的,看起来很丑。如何使用我的 FAB 上的颜色获取可绘制对象。谢谢。

这是我的矢量绘图

<vector android:height="42.859436dp" android:viewportHeight="42.94"
    android:viewportWidth="26.65" android:width="26.6dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#f0c419" android:pathData="M26.65,17A13.33,13.33 0,1 0,13.33 30.36,13.32 13.32,0 0,0 26.65,17"/>
    <path android:fillColor="#e64c3c" android:pathData="M13.33,3.7a13.21,13.21 0,0 1,8.14 2.8V0H5.18V6.5a13.26,13.26 0,0 1,8.15 -2.8"/>
    <path android:fillColor="#e64c3c" android:pathData="M13.33,30.36a13.26,13.26 0,0 1,-8.15 -2.8V42.94l8.15,-8.14 8.14,8.14V27.56a13.21,13.21 0,0 1,-8.14 2.8"/>
    <path android:fillColor="#ffe69f" android:pathData="M13.33,7.4l2.83,5.72l6.05,0.95l-4.29,4.45l1.33,5.91l-5.92,-2.57l-5.93,2.57l1.34,-5.91l-4.3,-4.45l6.05,-0.95l2.84,-5.72z"/>
</vector>

【问题讨论】:

  • here 所述,如果您的背景是彩色的,则添加app:tint="@null" 将解决问题

标签: android android-layout material-design floating-action-button


【解决方案1】:

你缺少一些属性。

这样做:

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_batch_gold"
    app:tint="@color/colorFabTint"
    app:backgroundTint="@color/white"
    app:layout_anchor="@id/bar" />

请注意 app:tintandroid:src attr 而不是 app:srcCompat

【讨论】:

  • 我试过了,但仍然存在同样的问题。我有一个可绘制的彩色矢量,但它是蓝色和黑色的
  • 你能张贴你得到的结果的截图吗?也发布你的矢量绘图。
猜你喜欢
  • 2023-02-23
  • 1970-01-01
  • 1970-01-01
  • 2017-08-26
  • 1970-01-01
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 2021-03-13
相关资源
最近更新 更多