android - Change shape solid color at runtime inside Drawable xml used as background -
i've drawable xml file (background.xml):
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape> ........... </shape> </item> <item android:id="@+id/shape_id"> <shape android:shape="rectangle"> <solid android:color="#ffefefef" /> </shape> </item> </layer-list>
used linearlayout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/background" android:id="@+id/layout_id" >
now need change shape shape_id
solid color @ runtime based on conditions. how this?
found me:
view v = findviewbyid(r.id.layout_id); layerdrawable bgdrawable = (layerdrawable)v.getbackground(); final gradientdrawable shape = (gradientdrawable) bgdrawable.finddrawablebylayerid(r.id.shape_id); shape.setcolor(----);
Comments
Post a Comment