android - how to change button background color as clicked action? -
---in android application ---
after button clicked,its background color changed required. clicked again,its color restore original color.
how implement it?
any response,thank you!
================================================================================== update: network,i find method achieve aim. design drawable color in xml this:
<drawable name="button_checked">#ffff0000</drawable>
in activity,use below code drawable object:
resources resource = getbasecontext().getresources(); checked_drawable = resource.getdrawable(r.drawable.button_checked);
in onclick function,according boolean variable:
setbackgrounddrawable(checked_mdrawable)
to set button background.
in js file put
$('#button').toggleclass('bg');
in css, have regular button css style
#button { background: white; }
and add
#button.bg { background: red; }
so when click on button turn background red, if click on again, turn white.
use whatever color / url want backgrounds.
Comments
Post a Comment