<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/iconSelector">
 
<!-- pressed -->
 
<item android:state_pressed="true" android:drawable="@drawable/btn_icon_hl" />
 
<!-- focused -->
 
<item android:state_focused="true" android:drawable="@drawable/btn_icon_hl" />
 
<!-- default -->
 
<item android:drawable="@drawable/btn_icon" />
</selector>

를 코드로 구현하기

StateListDrawable states = new StateListDrawable();
states
.addState(new int[] {android.R.attr.state_pressed},
    getResources
().getDrawable(R.drawable.pressed));
states
.addState(new int[] {android.R.attr.state_focused},
    getResources
().getDrawable(R.drawable.focused));
states
.addState(new int[] { },
    getResources
().getDrawable(R.drawable.normal));
imageView
.setImageDrawable(states);


+ Recent posts