2017-06-13 17 views
1

画像の間に透明な部分があるpng画像があります。私はその領域に色をプログラム的に設定しようとしていますが、機能していません。 XMLでAndroidの画像の背景色を設定する方法

この私の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で私は色を設定することができていますが、私はプログラム的にそのcolor.isを変更する必要があり、このcard_viewを使用して

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

属性とにかく私はこのプロパティをプログラム的に設定できますか?誰か助けてください。 how to fill color

+0

チェックオブジェクトは、それが色を設定する機能を有するCircularImageView'。 –

+0

私はしようとしているが動作していない。 – sunil

答えて

2

CircularImageViewはカスタム表示です。以下のようにプロパティを変更することができます。 `の

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

ありがとう、その作業。 – sunil

0
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); 
関連する問題