Search code examples
androidimageviewpicasso

Android and roundedimageview: how to change the border color


In my XML layout, I use this code to create a specific shape for my imageview:

 <com.makeramen.roundedimageview.RoundedImageView
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/avatar"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:src="@drawable/adduserprofile"
                android:scaleType="centerCrop"
                app:riv_border_width="5dip"
                app:riv_border_color="#ff9800"
                app:riv_mutate_background="true"
                app:riv_oval="false"
                app:riv_corner_radius_bottom_right="15dp"
                app:riv_corner_radius_top_left="15dp"
                app:riv_corner_radius_bottom_left="15dp"
                />

and then I load the image with Picasso in this way:

Picasso.get().load(url.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).networkPolicy(NetworkPolicy.NO_CACHE).into(p_avatar);

Is there any possibility to change the border color in Java by using Picasso or any other method? I would like to change the border color depending on some user's events.

Thank you!


Solution

  • You can use Transformation object to set properties of the shape. Use different Transformation object for different events.

    Transformation transformation = new RoundedTransformationBuilder()
          .borderColor(Color.BLACK)
          .borderWidthDp(3)
          .cornerRadiusDp(30)
          .oval(false)
          .build();
    
    Picasso.with(context)
    .load(url)
    .fit()
    .transform(transformation)
    .into(imageView);
    

    You should check the README of library before using it.