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

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -