如何在Android中设置图像的背景色

如何在Android中设置图像的背景色,android,background-color,transparent,Android,Background Color,Transparent,我有一个png图像,图像之间有一些透明区域。我试图以编程方式设置该区域的颜色,但它不起作用 这是我的xml布局 <?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:layou

我有一个png图像,图像之间有一些透明区域。我试图以编程方式设置该区域的颜色,但它不起作用

这是我的xml布局

<?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>

使用xml中的此card_视图,我可以设置颜色,但我需要以编程方式更改其颜色。是否仍可以以编程方式设置此属性?请任何人帮助我。

CircularImageView是一个自定义视图。您可以更改其属性,如下所示

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

检查
CircularImageView
的对象,它具有设置颜色的功能。我尝试了,但它不起作用。
 CircularImageView circularImageView = (CircularImageView)findViewById(R.id.iv_cat_icon);
    // Set Border
    circularImageView.setBorderColor(getResources().getColor(R.color.tabsScrollColor));
    circularImageView.setBorderWidth(10);
CircularImageView imageView = (CircularImageView)findViewById(R.id.iv_cat_icon);

Drawable color = new ColorDrawable(getResources().getColor(R.color.your_color));
Drawable image = getResources().getDrawable(R.drawable.your_drawable);

LayerDrawable ld = new LayerDrawable(new Drawable[]{color, image});
imageView.setImageDrawable(ld);