Search code examples
androidbackground-colortransparent

how to set background color of image in Android


I have png image which have some transparent area in between image. I am trying to set color programmatically to that area but its not working.

This is my xml layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.mikhaellopez.circularimageview.CircularImageView
    android:id="@+id/iv_cat_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:src="@drawable/del"
    card_view:civ_border_color="@color/tabsScrollColor" />
   </RelativeLayout>

in xml i have custom attribute

  xmlns:card_view="http://schemas.android.com/apk/res-auto

using this card_view in xml i am able to set color but i need to change programmatically its color.is there anyway i can set this property programatically? Please anyone help me out.how to fill color


Solution

  • CircularImageView is a custom view. You can change it's properties as shown below.

     CircularImageView circularImageView = (CircularImageView)findViewById(R.id.iv_cat_icon);
        // Set Border
        circularImageView.setBorderColor(getResources().getColor(R.color.tabsScrollColor));
        circularImageView.setBorderWidth(10);