tags:

views:

112

answers:

1

I have this resource for a Button

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;

    <item android:state_pressed="true">
        <shape>
            <solid android:color="@color/CLR_GREEN" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="10dp"
                android:right="10dp" android:bottom="10dp" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="@color/CLR_GREEN_DARK" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="10dp"
                android:right="10dp" android:bottom="10dp" />
        </shape>
    </item>
</selector>

And I refer to this button in code as greenBtn

How do I simulate its pressure without firing its onClick event? i.e. how do I make it change its background color as if it was pressed, stay in this state for half a second and then be back in its original state?

+1  A: 

View#setPressed(boolean)


I think your <item> without any states is overriding your first <item>. Try making it <item android:state_pressed="false">

Qberticus
already tried but... no, it doesn't work
klez
how about if you try that? :)
Qberticus
It's weird, the last one in the list is supposed to be the default one if none of the others match. I haven't played with the statelist stuff much but I do remember reading that it is pretty poorly documented and problematic to get right.
Qberticus
when I actually press the button it does change its background color, so I'm pretty sure I don't have to touch the xml.
klez
ok, re-tried. I was just putting it in the wrong place :/
klez