小编Moh*_*hit的帖子

类inf <unknown>时出错

我正试图在UI中工作.我正在尝试为列表条目设置stateListDrawable.我想要做的就是在按下项目时更改列表项目布局的颜色,并且在按下列表项目时我也想要更改文本的颜色.

我收到以下错误堆栈:

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)
Run Code Online (Sandbox Code Playgroud)

膨胀的XML如下:

<?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>
Run Code Online (Sandbox Code Playgroud)

如果我android:textColor从xml中删除属性,我可以让程序工作.有没有办法可以使用stateListDrawable来控制xml中的listitem的texColor?

stateListDrawable适用android:background于LinearLayout,但不适用于TextView的textColor属性.状态列表xml如下:

<?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" …
Run Code Online (Sandbox Code Playgroud)

android textview android-inflate xml-drawable

11
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-inflate ×1

textview ×1

xml-drawable ×1