Federico klez Culloca
Federico klez Culloca

Reputation: 27119

Simulate button press

I have this resource for a Button

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

    <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?

Upvotes: 0

Views: 1116

Answers (1)

Rich Schuler
Rich Schuler

Reputation: 41972

View#setPressed(boolean)


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

Upvotes: 2

Related Questions