java - android-how can a button remain in "clicked appearance" even after realease? -
in holo theme, click on button gets blue , shines moment. want button remains @ appearance, , @ next click comes normal appearance. how that?
update: code:
public class homeactivity extends sherlockactivity { org.holoeverywhere.widget.button bt; boolean ispressed = false; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.home_layout); bt = (org.holoeverywhere.widget.button) findviewbyid(android.r.id.button1); bt.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { if (event.getaction() == motionevent.action_up) { if (!ispressed) { ispressed = true; } else { ispressed = false; } bt.setpressed(ispressed); } return true; } }); } }
first of all, can default images used sdk(button, check box, whatever is) location ->
~\android-sdk\platforms\android-18\data\res\drawable-hdpi
here i'm looking api-18. use whatever version support holo theme.
from there, can find image btn_default_pressed_holo_dark.9.png .
copy-paste project drawable-hdpi folder. first step. now,
public class mainactivity extends activity { button b; drawable back; int flag=0; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); b=(button) findviewbyid(r.id.button1); back=b.getbackground(); b.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if(flag==0){ b.setbackgroundresource(r.drawable.btn_default_pressed_holo_dark); flag=1; } else{ flag=0; b.setbackground(back); } } }); } }
check :)
Comments
Post a Comment