2012-06-18 5 views
0

내 레이아웃에 버튼을 눌렀을 때 이미지를 변경해야하는 버튼이 있습니다. 나는 선택기 XML을 가진다. 여기상태를 눌렀을 때 Android 이미지 버튼의 색상이 변경되지 않습니다.

<ImageButton 
      android:id="@+id/cwcfwdvcs" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:clickable="true" 
      android:layout_marginTop="16dp" 
      android:background="@drawable/button_add_to_favorites_unactive" 
      android:drawable="@drawable/add_to_favorites" 
      android:text="Favotites"/> 

선택 add_to_favorites.xml됩니다 : 여기에 버튼이

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:drawable="@drawable/button_add_to_favorites_active" 
     android:state_checked="true" /> 
<item android:drawable="@drawable/button_add_to_favorites_unactive" /> 

답변

0

다음과 같은 코드처럼 버튼을 선택 상태를 사용해야합니다 즉, (고해상도/드로어 블/사진 button.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/button_add_to_favorites_active"> 

</item> 

<item android:state_focused="true" android:drawable="@drawable/button_add_to_favorites_active"> 

</item> 

<item android:drawable="@drawable/button_add_to_favorites_active">   

</item> 
</selector> 
관련 문제