图片选择器

TextView中textColor属性 报错

代码:


attr:


FATAL EXCEPTION: main
                                                   Process: cn.fengxing.com.mcppictureselect, PID: 31417
                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.fengxing.com.mcppictureselect/cn.fengxing.com.mcppictureselect.MainActivity}: android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class TextView
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3174)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3269)
                                                       at android.app.ActivityThread.-wrap12(Unknown Source:0)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
                                                       at android.os.Handler.dispatchMessage(Handler.java:108)
                                                       at android.os.Looper.loop(Looper.java:166)
                                                       at android.app.ActivityThread.main(ActivityThread.java:7380)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)
                                                    Caused by: android.view.InflateException: Binary XML file line #19: Binary XML file line #19: Error inflating class TextView
                                                    Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class TextView
                                                    Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f010000 a=-1}
                                                       at android.content.res.TypedArray.getColorStateList(TypedArray.java:569)
                                                       at android.widget.TextView.(TextView.java:1291)
                                                       at android.widget.TextView.(TextView.java:872)
                                                       at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:62)
                                                       at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:58)
                                                       at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
                                                       at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1029)
                                                       at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1087)
                                                       at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:47)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:783)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                       at cn.fengxing.com.mcppictureselect.MainActivity.onCreate(MainActivity.java:11)
                                                       at android.app.Activity.performCreate(Activity.java:7352)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3127)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3269)
                                                       at android.app.ActivityThread.-wrap12(Unknown Source:0)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)
                                                       at android.os.Handler.dispatchMessage(Handler.java:108)
                                                       at android.os.Looper.loop(Looper.java:166)
                                                       at android.app.ActivityThread.main(ActivityThread.java:7380)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)

原因是TypeArray转换是没有找到值,导致的。
解决办法:我给直接给定了颜色值。
不是好的解决方案:


前景色 foreground

android:foreground="?selectableItemBackground"

foreground 也就是前景色,它与background相对应,顾名思义,它指定的drawable是在view视图的上方绘制的。

image.png

在布局中使用?attr

  1. 在布局文件中定义 例如textColor

  1. 在attr文件中定义

  1. 在style样式中定义
@color/bottom_toolbar_bg
  1. 在color中定义
#FFFFFF

完成这四个步骤,在布局文件中使用?attr就是使用到对应的color文件中的颜色。

你可能感兴趣的:(图片选择器)