微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – AppCompat,Vectors和4.1.2的奇怪崩溃

当我尝试在 Android v4.1.2(API 16)上运行我的应用程序时,我收到了一个非常奇怪的崩溃报告.我在旧款手机上遇到以下错误

07-10 16:15:52.188 5496-5496/com.amplified.music.debug E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amplified.music.debug/com.amplified.music.activity.MainActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class ImageButton
          at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2110)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
          at android.app.ActivityThread.access$700(ActivityThread.java:143)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:137)
          at android.app.ActivityThread.main(ActivityThread.java:4950)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:511)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
          at dalvik.system.NativeStart.main(Native Method)
       Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class ImageButton
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
          at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
          at com.amplified.music.fragment.PlayerFragment.onCreateView(PlayerFragment.java:233)
          at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
          at android.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:1036)
          at android.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:1230)
          at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1332)
          at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2288)
          at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
          at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
          at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
          at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
          at roboguice.activity.RoboFragmentActivity.onCreateView(RoboFragmentActivity.java:163)
          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
          at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
          at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
          at com.amplified.music.activity.RoboAppCompatActivity.setContentView(RoboAppCompatActivity.java:55)
          at com.amplified.music.activity.MainActivity.onAuthenticatedCustomer(MainActivity.java:87)
          at com.amplified.music.activity.MusicActivity.onCreate(MusicActivity.java:72)
          at android.app.Activity.performCreate(Activity.java:5179)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
          at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2074)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135) 
          at android.app.ActivityThread.access$700(ActivityThread.java:143) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 
          at android.os.Handler.dispatchMessage(Handler.java:99) 
          at android.os.Looper.loop(Looper.java:137) 
          at android.app.ActivityThread.main(ActivityThread.java:4950) 
          at java.lang.reflect.Method.invokeNative(Native Method) 
          at java.lang.reflect.Method.invoke(Method.java:511) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) 
          at dalvik.system.NativeStart.main(Native Method) 
       Caused by: java.lang.NumberFormatException: Invalid int: "res/color/abc_primary_text_material_dark.xml"
          at java.lang.Integer.invalidInt(Integer.java:138)
          at java.lang.Integer.parse(Integer.java:375)
          at java.lang.Integer.parseInt(Integer.java:366)
          at com.android.internal.util.XmlUtils.convertValuetoInt(XmlUtils.java:123)
          at android.content.res.TypedArray.getInt(TypedArray.java:254)

我在我的gradle构建文件中使用了vectorDrawables.useSupportLibrary = true设置的向量.我使用以下代码来指代我的图像:

<ImageButton android:id="@+id/playQueueButton"
        android:layout_marginRight="20dp"
        android:layout_marginEnd="20dp"
        android:layout_height="48dp"
        android:layout_width="48dp"
        style="@style/AppTheme.Button.Flat.Inverse"
        app:srcCompat="@drawable/ic_queue_music_black_24dp"/>

我的风格定义如下:

<style name="AppTheme.Button.Flat" parent="Widget.AppCompat.Button.Borderless">
    <item name="android:layout_margin">0dp</item>
    <item name="android:tint">?android:textColorPrimary</item>
    <item name="android:textColor">?android:textColorPrimary</item>
</style>

<style name="AppTheme.Button.Flat.Inverse" parent="AppTheme.Button.Flat">
    <item name="android:tint">?android:textColorPrimaryInverse</item>
    <item name="android:textColor">?android:textColorPrimaryInverse</item>
    <item name="android:background">@drawable/home_button_selector</item>
</style>

我在网上找不到有关此错误的任何详细信息.我不确定它为什么会崩溃.

解决方法

@chubbsondubs似乎只能对5.0及以上的drawables应用色调?这是文档[官方Android文档]

[1] https://developer.android.com/training/material/drawables.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐