I used a function like
void setHighlighted(boolean highlight) {
button.setBackgroundResource( highlight
? R.drawable.bbg_pressed
: R.drawable.button_background);
}
where button_background is a selector defined in
button_backgroung.xml
:
<?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/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
That is, this code does not interfere with the pressed state used by the Android framework; instead, it changes the background so that the button looks pressed.