android – 错误膨胀类

前端之家收集整理的这篇文章主要介绍了android – 错误膨胀类前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在UI中工作.我正在尝试为列表条目设置stateListDrawable.所有我想要做的是在按下项目时更改列表项布局的颜色,而在列表项目被按下的同时,我也想改变文本的颜色.

我收到以下错误堆栈:

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

充斥的XML如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/help_list_container"
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content"
  6. android:padding="5dip"
  7. android:background="@drawable/default_list_selection">
  8. <TextView android:id="@+id/help_list_text"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:textSize="16sp"
  12. android:textColor="@drawable/help_text_color">
  13. </TextView>
  14. </LinearLayout>

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

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

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

任何回应都不胜感激.

解决方法

错误地使用drawable来更改TextView的textColor.相反,我应该使用一个ColorStateList
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3. <item android:state_pressed="true" android:color="@color/white" />
  4. <item android:color="@color/black"/>
  5. </selector>

猜你在找的Android相关文章