我想在我的RecyclerView可绘制着色预棒棒糖
Drawable likeDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_thumb_up);
Drawable likeWrappedDrawable = DrawableCompat.wrap(likeDrawable);
DrawableCompat.setTint(likeWrappedDrawable,ContextCompat.getColor(getActivity(), android.R.color.white));
holder.ivLike.setImageDrawable(likeWrappedDrawable);
使用下面的代码使用绘制着色现在,所有这一切都是在的RecyclerView适配器
的onBindViewHolder
正在做我根据该列表项的状态在三种颜色之间更改此色调。这对于Lolipop和以上版本都适用,但在此版本以下,列表项的颜色是不可预测的。有时它会显示正确的颜色,但在刷新列表时有时会变成其他颜色。
任何即使在这里做错了或在棒棒糖上的调色东西在这种特殊情况下仍然无法使用?
更新 包括我onBindViewHolder
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
...
Drawable likeDrawable =
ContextCompat.getDrawable(getActivity(), R.drawable.ic_thumb_up);
Drawable likeWrappedDrawable = DrawableCompat.wrap(likeDrawable);
holder.tvLikeCount.setTextColor(ResUtil.getColor(R.color.light_font,
getActivity()));
DrawableCompat.setTint(likeWrappedDrawable,
ContextCompat.getColor(getActivity(), android.R.color.white));
if (tweetModel.isFavorited()) {
DrawableCompat.setTint(likeWrappedDrawable,
ContextCompat.getColor(getActivity(), android.R.color.holo_blue_light));
}
holder.ivLike.setImageDrawable(likeWrappedDrawable);
}
ic_thumb_up是什么样的可绘制?只是一个PNG,或基于XML的可绘制? – alanv
简单的白色PNG –
我们可以有'onBindViewHolder'的完整代码吗? –