2011-02-17 2 views
11

UI에서 작업하고 있습니다. 목록 항목에 stateListDrawable을 설정하려고합니다. 내가하려는 것은 항목을 누를 때 목록 항목의 레이아웃의 색상을 변경하는 것 뿐이며 목록 항목을 누르고있는 동안 텍스트의 색상도 변경하려고합니다. 나는에서 android:textColor 속성을 제거하면클래스를 부 풀릴 때 오류가 발생했습니다. <unknown>

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/help_list_container" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dip" 
    android:background="@drawable/default_list_selection"> 
    <TextView android:id="@+id/help_list_text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="16sp" 
     android:textColor="@drawable/help_text_color"> 
    </TextView> 
</LinearLayout> 

내가 작동하도록 프로그램을 얻을 수 있습니다

E/AndroidRuntime( 360): FATAL EXCEPTION: main 
E/AndroidRuntime( 360): android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> 
E/AndroidRuntime( 360): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 
E/AndroidRuntime( 360): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
E/AndroidRuntime( 360): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 
E/AndroidRuntime( 360): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 
E/AndroidRuntime( 360): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
E/AndroidRuntime( 360): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
E/AndroidRuntime( 360): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 

팽창되는 XML은 다음과 같다 :

나는 다음과 같은 오류 스택을 얻고있다 xml. stateListDrawable을 사용하여 XML에서 listitem의 texColor를 제어 할 수있는 방법이 있습니까?

stateListDrawable은 LinearLayout에서 android:background으로 작동하지만 TextView의 textColor 속성에는 해당하지 않습니다. 상태 목록 xml은 다음과 같습니다.

모든 응답을 보내 주시면 감사하겠습니다.

답변

16

나는 드로어 블을 사용하여 TextView의 textColor를 잘못 변경하고있었습니다. 대신 ColorStateList를 사용해야합니다.

<?xml version="1.0" encoding="UTF-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" android:color="@color/white" /> 
    <item android:color="@color/black"/> 
</selector> 
관련 문제