I have a recyclerview and I need to modify the color of a drawable inside OnBindViewHolder, but I can't access the ID of my XML file for that.
I need to access the item with id circler_center and set a different color
My xml
`
<item
android:id="@+id/circle_center"
android:gravity="center">
<shape android:shape="oval">
<size android:width="58dp"
android:height="58dp"></size>
<solid android:color="#E2D5D5"></solid>
</shape>
</item>
<item>
<shape android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false">
<solid android:color="@color/white"></solid>
</shape>
</item>
<item>
<shape android:shape="ring"
android:thicknessRatio="8"
android:useLevel="true">
<solid android:color="#ffff00"></solid>
</shape>
</item>
`
My onBindViewHolder
´ @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
Nivels_of_Screen_Middle nivels = list.get(position).get(0);
MyviewHolder Holder = (MyviewHolder)holder;
Holder.progressBar.getProgressDrawable()
.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
Holder.progressBar.setProgress(nivels.getProgressBar());
Holder.textView.setText(nivels.getTextView());
Holder.imageView.setImageResource(nivels.getImageView());
} ´
I tried to do the following, used the holder.progressbar.getprogressDrawable (). Setcolorfilter (color.black, porterduff.mode.src_atop); However, the entire progress bar was painted black and not just the item with the ID circler_center
Option 1
It looks like item with id
circle_centercan have only two states: 1)it is filled with colorE2D5D52)it is filled withColor.BLACK. Is this assumption correct? If so, you can create two separatelayer-listdrawables, which will differ bycircle_centeritem implementation. And you just swap them dynamically.Option 2