风格=" @风格/ Widget.AppCompat.Button.Colored"强制关闭申请

时间:2016-03-31 05:39:22

标签: android button styles android-appcompat

我在尝试使用style="Widget.AppCompat.Button.Colored"时遇到错误。使用android支持库版本23.2.1。 我的xml文件:

<Button
   android:layout_width = "140dp"
   android:layout_height = "90dp"
   android:text = "Camera"
   android:id = "@+id/cameraButt"
   android:textAllCaps = "false"
   android:textColor = "@color/textColorPrimary"
   android:layout_marginLeft = "5sp"
   android:layout_marginRight = "5sp"
   android:layout_marginTop = "4sp"
   style="@style/Base.Widget.AppCompat.Button.Colored"/>

它在5.0 ++版本中完美运行,但在棒棒糖前没有。

logcat的:

03-30 11:29:10.346 19914-19914/com.emanuel.ocrwithabilities E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.emanuel.ocrwithabilities, PID: 19914
                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emanuel.ocrwithabilities/com.emanuel.ocrwithabilities.MainActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class Button
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
                                                                              at android.app.ActivityThread.access$800(ActivityThread.java:141)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:136)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5052)
                                                                              at java.lang.reflect.Method.invokeNative(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:515)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
                                                                              at dalvik.system.NativeStart.main(Native Method)
                                                                           Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class Button
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                              at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
                                                                              at com.emanuel.ocrwithabilities.MainActivity.onCreate(MainActivity.java:61)
                                                                              at android.app.Activity.performCreate(Activity.java:5245)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249) 
                                                                              at android.app.ActivityThread.access$800(ActivityThread.java:141) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:136) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5052) 
                                                                              at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                              at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                              at dalvik.system.NativeStart.main(Native Method) 
                                                                           Caused by: java.lang.NullPointerException
                                                                              at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:671)
                                                                              at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:107)
                                                                              at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:608)
                                                                              at android.support.v7.widget.AppCompatDrawableManager.tintDrawable(AppCompatDrawableManager.java:773)
                                                                              at android.support.v7.widget.AppCompatBackgroundHelper.applySupportBackgroundTint(AppCompatBackgroundHelper.java:118)
                                                                              at android.support.v7.widget.AppCompatBackgroundHelper.setInternalBackgroundTint(AppCompatBackgroundHelper.java:136)
                                                                              at android.support.v7.widget.AppCompatBackgroundHelper.loadFromAttributes(AppCompatBackgroundHelper.java:53)
                                                                              at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:66)
                                                                              at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:58)
                                                                              at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
                                                                              at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
                                                                              at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
                                                                              at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:400) 
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                              at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
                                                                              at com.emanuel.ocrwithabilities.MainActivity.onCreate(MainActivity.java:61) 
                                                                              at android.app.Activity.performCreate(Activity.java:5245) 
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164) 
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249) 
                                                                              at android.app.ActivityThread.access$800(ActivityThread.java:141) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:136) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5052) 
                                                                              at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                              at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                              at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

请将此添加到您的gradle依赖项中,看看它是否有效并让我知道

    compile 'com.android.support:design:23.2.1'