更改ImageView

时间:2018-04-04 02:35:31

标签: android kotlin picasso

我使用Picasso将图像加载到ImageView中。

但问题是,当我加载图像时,它有一个白色背景,我的应用程序背景有另一种颜色。我想将我加载的图像的白色转换为我的应用程序的主要颜色。

这是我的代码,但它不起作用,我猜不出原因。

picasso.load(data[i].image)//download URL
        .fit()
        .centerInside()
        .error(R.drawable.com_facebook_profile_picture_blank_portrait)//if failed
        .into(viewHolder.image)
viewHolder.image?.setBackgroundColor(ResourcesCompat.getColor(context.resources, R.color.colorPrimary, null))

这是我的xml:

<ImageView
    android:id="@+id/item_image"
    android:layout_width="100dp"
    android:layout_height="80dp"
    android:background="@color/colorPrimary"
    android:src="@drawable/com_facebook_profile_picture_blank_portrait"
    app:layout_constraintEnd_toEndOf="@id/inventory_item_guideline"/>

enter image description here

我想将白色背景更改为原色。

1 个答案:

答案 0 :(得分:0)

您需要使用占位符在图片加载前显示任何图片或颜色。

.placeholder(R.color.colorPrimary)
相关问题