我在安卓工作室中使用回收器视图,每个项目都有一个可绘制对象。如何通过单击特定位置来更改可绘制对象的颜色?


public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public ImageView img_FurnishIamge;
public FontTextView tv_FurnishText;
public ViewHolder(View itemView) {
super(itemView);
img_FurnishIamge=(ImageView)itemView.findViewById(R.id.img_furnishessImage);
tv_FurnishText=(FontTextView)itemView.findViewById(R.id.tv_furnishesText);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos=getAdapterPosition();
switch (pos){
case 0:
Toast.makeText(v.getContext(), "00000", Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(v.getContext(), "11111", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(v.getContext(), "22222", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(v.getContext(), "33333", Toast.LENGTH_SHORT).show();
break;
case 4:
Toast.makeText(v.getContext(), "44444", Toast.LENGTH_SHORT).show();
break;
case 5:
Toast.makeText(v.getContext(), "55555", Toast.LENGTH_SHORT).show();
break;
case 6:
Toast.makeText(v.getContext(), "66666", Toast.LENGTH_SHORT).show();
break;
}
}
}); //applying clickListner to the Item.
}

您可以像这样更改图像视图中图像的颜色

ColorFilter filter = new LightingColorFilter(Color.BLACK, Color.parseColor("yourcolorcode"));
imageView.setColorFilter(filter );

最新更新