编辑我做了建议的更改,但仍然收到相同的错误,如下所示。Android:在xml中声明颜色
我有一个布局,我试图设置背景颜色动态响应点击等。
这是布局的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_pare"
android:gravity="center_vertical"
android:background="@drawable/custom_style"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView"/>
</RelativeLayout>
而这正是我想声明的颜色,存储在可绘制/ custom_style.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:color="#ff0000" android:state_selected="true"/>
<item android:color="#ffffff" android:state_pressed="true" />
<item android:color="#e3e3e3"/>
</selector>
问题是当我尝试运行此应用程序崩溃,出现以下错误:
03-24 16:29:50.540: E/AndroidRuntime(17643): FATAL EXCEPTION: main
03-24 16:29:50.540: E/AndroidRuntime(17643): android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
03-24 16:29:50.540: E/AndroidRuntime(17643): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
03-24 16:29:50.540: E/AndroidRuntime(17643): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)...
看到我的答案有错误,当你声明你的颜色。 – Fllo
在你的XML中,你已经设置了layout_height =“fill_pare”,如果你把fill_parent(或者更好的match_parent)仍然存在错误?如果错误仍然存在,您可以发布崩溃活动的onCreate方法的代码? – jaumebd
@jaumebd我认为你只是找到解决方案! ^^ – Fllo