开发者

Error inflating class <unknown>

I am trying to work my way in UI. I am trying to set stateListDrawable for list entries. All I am trying to do is change the color of the list item's layout when the item is pressed, and while the list item is pressed I want to change the color of the text as well.

I am getting the following error stack:

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.LayoutInfl开发者_运维知识库ater.inflate(LayoutInflater.java:276)

The XML that is inflated is the following:

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

I can get the program to work if I remove the android:textColor property from the xml. Is there a way I can use a stateListDrawable to control the texColor of a listitem from the xml?

The stateListDrawable works for android:background in LinearLayout, but it won't for the textColor property of TextView. The state list xml is the following:

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

Any response would be appreciated.


I was wrongly using a drawable to change the textColor of a TextView. Instead, I should have used a 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜