无法将索引1处的值转换为color:type = 0x5

时间:2018-02-10 13:53:26

标签: android

只要我将标签应用:shadowColor =“@ android:color / black”和其他代码,我的应用程序崩溃了。

       <info.hoang8f.widget.FButton
        android:id="@+id/btnSignUp"
        android:layout_width="14dp"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:layout_weight="1"
        android:text="Sign Up"
        android:textColor="@android:color/white"
        app:buttonColor="@color/btnSignUp"
        app:shadowColor="@android:color/black"
        app:shadowEnabled="true"
        app:shadowHeight="5dp"
        app:cornerRadius="4dp"

         />

这是logcat

02-10 21:00:20.793 15027-15027/edmt.dev.androideatit E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: edmt.dev.androideatit, PID: 15027
                                                                       java.lang.RuntimeException: Unable to start activity ComponentInfo{edmt.dev.androideatit/edmt.dev.androideatit.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                                        Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
                                                                        Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class info.hoang8f.widget.FButton
                                                                        Caused by: java.lang.reflect.InvocationTargetException
                                                                           at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                           at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                           at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
                                                                           at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                           at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                           at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                           at edmt.dev.androideatit.MainActivity.onCreate(MainActivity.java:17)
                                                                           at android.app.Activity.performCreate(Activity.java:6662)
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                                        Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
                                                                           at android.content.res.TypedArray.getColor(TypedArray.java:463)
                                                                           at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
                                                                           at info.hoang8f.widget.FButton.(FButton.java:52)
                                                                           at java.lang.reflect.Constructor.newInstance0(Native Method) 
                                                                           at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) 
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
                                                                           at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
                                                                           at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) 
                                                                           at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
                                                                           at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
                                                                           at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                                                                           at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                                           at edmt.dev.androideatit.MainActivity.onCreate(MainActivity.java:17) 
                                                                           at android.app.Activity.performCreate(Activity.java:6662) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:154) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 

2 个答案:

答案 0 :(得分:0)

您没有关闭shadowHeight标记。您应该关闭app:shadowHeight="5dp"

答案 1 :(得分:0)

我已经通过替换 build.gradle 中的 minSdkVersion 23 解决了同样的问题,并且您还需要使用 java 文件中的以下代码行来转换它。

<块引用>

按钮 b = (Button)findViewById(R.id.btnId);

希望对未来有所帮助。