Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 错误膨胀类大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在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)

充斥的XML如下:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://scheR_125_11845@as.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>

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

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

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

任何回应都不胜感激.

解决方法

错误地使用drawable来更改TextView的textColor.相反,@R_319_10675@用一个ColorStateList
<?xml version="1.0" encoding="UTF-8"?>
<SELEctor xmlns:android="http://scheR_125_11845@as.android.com/apk/res/android">
   <item android:state_pressed="true" android:color="@color/white" />
   <item android:color="@color/black"/>
 </SELEctor>

大佬总结

以上是大佬教程为你收集整理的android – 错误膨胀类全部内容,希望文章能够帮你解决android – 错误膨胀类所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。