2011-02-17 12 views
11

Estoy intentando abrirme camino en la interfaz de usuario. Estoy tratando de establecer stateListDrawable para las entradas de la lista. Todo lo que intento hacer es cambiar el color del diseño del elemento de la lista cuando se presiona el elemento, y mientras se presiona el elemento de la lista, también quiero cambiar el color del texto.Error al inflar la clase <unknown>

estoy recibiendo el siguiente pila de errores:

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) 

El XML que se infla es la siguiente:

<?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> 

puedo conseguir el programa para trabajar si quito la propiedad android:textColor de la xml. ¿Hay alguna manera de que pueda usar un stateListDrawable para controlar el texColor de un elemento de lista del xml?

stateListDrawable funciona para android:background en LinearLayout, pero no para la propiedad textColor de TextView. La lista de estado xml es la siguiente:

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

Cualquier respuesta sería apreciada.

Respuesta

16

Estaba usando incorrectamente un drawable para cambiar el textColor de un TextView. En su lugar, debería haber usado una 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> 
Cuestiones relacionadas