自定义分离器引起例外
我有自定义的视图分离器,由于某种原因,其背景颜色选择器正在引起异常。如果我更改背景颜色以静态价值的功能完美。
这个问题的原因是什么?
<include
layout="@layout/field_underline"
android:id="@+id/input_underline"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="@+id/main_field"/>
field_underline.xml
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/field_underline_color" />
field_underline_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="200"
android:enterFadeDuration="200">
<item
android:state_enabled="false"
android:state_checked="false"
android:state_activated="false"
android:alpha="0.4"
android:color="@color/content_50"
/>
<item
android:state_enabled="true"
android:state_checked="true"
android:state_activated="false"
android:alpha="1"
android:color="@color/invalid"
/>
<item
android:state_enabled="true"
android:state_checked="false"
android:state_activated="true"
android:alpha="1"
android:color="@color/primary"
/>
<item
android:alpha="1"
android:color="@color/content_50"/>
</selector>
异常:
android.view.InflateException: Binary XML file line #71: Binary XML file line #4: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:965)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
分离器需要这些行动吗?似乎并非如此。
Does the separator need those actions? It doesn't seem so.
您需要在logcat中向下看较低,才能找到真正的错误。我相信,如果您向下滚动,您会看到类似于以下错误的内容:
如果您查看 statelistdrawable>
则标签需要一个“可绘制”属性或儿童标记,以定义可绘制的drawable。 href =“ https://developer.android.com/guide/topics/resources/drawable-resource#statelist ”
您缺少可绘制的属性。
You need to look lower down in the logcat to find the true error. I believe that if you scroll down, you will see something similar to the following error:
Now, if you look at the documentation for a StateListDrawable, you will see the following:
According to this same documentation:
You are missing the drawable attribute.