It is simple to specify the view background drawable with normal/pressed states in the .xml, like
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:state_enabled="true" android:state_pressed="false"
android:color="@color/setting_color_select" />
<item android:state_pressed="true" android:color="@color/setting_color_select" />
</selector>
But how to create a drawable programmably with the focus or pressed state specified? I didn't find the answer in the developer docs.