【发布时间】:2015-09-08 06:00:08
【问题描述】:
我想从 xml 中扩充视图,就像这样:
View textView = LayoutInflater.from(context).inflate(R.layout.item_classify_left, null);
但我的代码有错误:
android.view.InflateException: Binary XML file line #2: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.inflate(LayoutInflater.java:472)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
有布局:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dip"
android:gravity="center"
android:textColor="@drawable/item_classify_left_textcolor_selector"
android:background="@drawable/item_classify_left_background_selector" />
我发现当我删除 android:textColor 和 android:background 时,它工作正常。但我真的需要选择器。有选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/main_background_color" />
<item android:color="@color/item_classify_text_background_normal" />
</selector>
我该如何解决这个问题?
【问题讨论】:
标签: android layout-inflater android-inflate