我做了一个搜索,发现了几个关于这个主题的问题,但没有一个对我有好处。
我试图将样式颜色附加到textview,并且它一直失败
tehilim_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<com.karriapps.tehilimlibrary.utils.TehilimTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/titleColor"
android:padding="10dp"
android:textSize="16sp"
android:text="@string/yehiTitle"
android:layout_gravity="@integer/title_gravity"
/>
<com.karriapps.tehilimlibrary.utils.TehilimTextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="start"
android:text="@string/yehiBefore"
android:padding="10dp"
android:textColor="?attr/text_color"
/>
</LinearLayout>
attr.xml
<attr name="text_color" format="reference"/>
style.xml
<item name="text_color">@color/text_color</item>
text_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="#000000"/>
<item android:state_pressed="true" android:state_enabled="false" android:color="#000000" />
<item android:state_enabled="false" android:color="#000000" />
<item android:color="#000000"/>
</selector>
异常日志
04-25 09:04:10.857: E/AndroidRuntime(3357): FATAL EXCEPTION: main
04-25 09:04:10.857: E/AndroidRuntime(3357): Process: com.karriapps.tehilimlibrary, PID: 3357
04-25 09:04:10.857: E/AndroidRuntime(3357): android.view.InflateException: Binary XML file line #43: Error inflating class
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-25 09:04:10.857: E/AndroidRuntime(3357): at com.karriapps.tehilimlibrary.MainFragment$TehilimAdapter.getView(MainFragment.java:199)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.AbsListView.obtainView(AbsListView.java:2263)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.ListView.onMeasure(ListView.java:1175)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:639)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
04-25 09:04:10.857: E/AndroidRuntime(3357): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-25 09:04:10.857: E/AndroidRuntime(3357): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.View.measure(View.java:16497)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.Choreographer.doFrame(Choreographer.java:544)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.os.Handler.handleCallback(Handler.java:733)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.os.Handler.dispatchMessage(Handler.java:95)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.os.Looper.loop(Looper.java:136)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-25 09:04:10.857: E/AndroidRuntime(3357): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 09:04:10.857: E/AndroidRuntime(3357): at java.lang.reflect.Method.invoke(Method.java:515)
04-25 09:04:10.857: E/AndroidRuntime(3357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-25 09:04:10.857: E/AndroidRuntime(3357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-25 09:04:10.857: E/AndroidRuntime(3357): at dalvik.system.NativeStart.main(Native Method)
04-25 09:04:10.857: E/AndroidRuntime(3357): Caused by: java.lang.reflect.InvocationTargetException
04-25 09:04:10.857: E/AndroidRuntime(3357): at java.lang.reflect.Constructor.constructNative(Native Method)
04-25 09:04:10.857: E/AndroidRuntime(3357): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
04-25 09:04:10.857: E/AndroidRuntime(3357): ... 45 more
04-25 09:04:10.857: E/AndroidRuntime(3357): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f010075 a=-1}
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.content.res.Resources.loadColorStateList(Resources.java:2237)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.content.res.TypedArray.getColorStateList(TypedArray.java:343)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.TextView.(TextView.java:960)
04-25 09:04:10.857: E/AndroidRuntime(3357): at android.widget.TextView.(TextView.java:618)
04-25 09:04:10.857: E/AndroidRuntime(3357): at com.karriapps.tehilimlibrary.utils.TehilimTextView.(TehilimTextView.java:14)
04-25 09:04:10.857: E/AndroidRuntime(3357): ... 48 more