StateListDrawable 请看例题:
Drawable btnDraw = getResources().getDrawable(R.drawable.dialog_btn);
Drawable focusDraw = getResources()
.getDrawable(R.drawable.highlight_72x4);
private Drawable buttonBg = new StateListDrawable() {
public void draw(Canvas canvas) {
Rect r = canvas.getClipBounds();
btnDraw.setBounds(r.left, r.top, r.right,
r.top + btnDraw.getIntrinsicHeight()
- focusDraw.getIntrinsicHeight());
btnDraw.draw(canvas);
int[] state = getState();
if (state != null) {
for (int i = 0; i < state.length; i++) {
if (state[i] == android.R.attr.state_focused
|| state[i] == android.R.attr.state_selected
|| state[i] == android.R.attr.state_checked
|| state[i] == android.R.attr.state_pressed) {
focusDraw
.setBounds(
r.left,
r.bottom
- focusDraw
.getIntrinsicHeight(),
r.right, r.bottom);
focusDraw.draw(canvas);
return;
}
}
}
}