android - stateListDrawable help -
so made these 2 buttons.
i want able click button made , have button change whited-out image of original button instead of on , off states have in toggle button.
so far i've figured out statelistdrawable xml, placed in 3 drawable folders. thats place i've found belongs, however, don't know reference .xml file main. do programmatically? if point me in right direction of tutorial. android dev page foreign me. , have posted buttons have better idea, can't until more points. gimmick!
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/toggle_selection_pressed" /> <item android:drawable="@drawable/toggle_selection" /> </selector>
you'll need variable keep state of button. put in main class declaration
int isclicked = 0; button.setonclicklistener(new onclicklistener() { public void onclick(view v) { if (isclicked == 0){ demo_button.setsetimageresource(r.drawable.secondimage); isclicked = 1; } else{ demo_button.setsetimageresource(r.drawable.firstimage); isclicked = 0; } } }
Comments
Post a Comment