Thursday, May 10, 2018

Change background of custom drawable

1.listbox_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/listbg">
    <shape android:shape="rectangle" >
        <stroke
            android:width="2dip"
            android:color="#ffffff" />
        <solid android:color="#0000"/>
    </shape>
</item>
</layer-list>


2.MainActivity.java

Drawable tempDrawable = getResources().getDrawable(R.drawable.listbox_bg);
LayerDrawable bubble = (LayerDrawable) tempDrawable;
GradientDrawable solidColor = (GradientDrawable) bubble.findDrawableByLayerId(R.id.listbg);
solidColor.setColor(Color.parseColor(colorCode));

This Is The Newest Post


EmoticonEmoticon