Android: change button color programmatically with defined drawable -
i have:
public button[] getbuttons(int buttoncount, list<string> buttonheaders, context activity) { button[] result = new button[buttoncount]; (int = 0; < buttoncount; i++) { result[i] = new button(activity); result[i].setid(i); result[i].settext(buttonheaders.get(i)); result[i].setbackgroundresource(r.drawable.buttons_shape); result[i].setbackgroundcolor(randomcolor(activity)); result[i].settextcolor(activity.getresources().getcolor(r.color.white)); result[i].setwidth(360); result[i].setheight(100); } return result; }
but in drawable is:
<solid android:color="@color/white"/> <corners android:bottomrightradius="10dp" android:bottomleftradius="10dp" android:topleftradius="10dp" android:toprightradius="10dp"/>
but define program color, because color random, , when change background return default design (ps. sorry english :p)
you can't both.. either can view.setbackgrounddrawable(drawable); or view.setbackgroundcolor(color);
Comments
Post a Comment