使用Android 6.0向ActionMenuItemView充气时出错。 (sdk 23)

时间:2016-07-10 08:39:16

标签: android sdk upgrade android-6.0-marshmallow appcompat-v7-r23

我叫Victor。我已经被这个问题困扰了几个小时,无法解决问题。以下是发生的事情:

我有一个应用程序会自动加载此主题以启用补充工具栏功能:(AppTheme.ActionBar)

<!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/black_opaque</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">#212121</item>
        <item name="android:textColorSecondary">#727272</item>
        <item name="textColorError">@color/design_textinput_error_color_dark</item>
    </style>


    <style name="AppTheme.ActionBar">
        <item name="windowActionBar">true</item>
        <item name="windowNoTitle">false</item>

然后,我使用getWindow().requestFeature(Window.FEATURE_ACTION_BAR);获得支持ActionBar。

在低于6.0的Android版本中,它很好。使用Android 6.0,它会自动崩溃并给我这个错误:

07-10 08:16:18.894 3058-3058/com.example.com E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.example.com, PID: 3058
                                                                            android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.v7.view.menu.ActionMenuItemView
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161)
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180)
                                                                                at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192)
                                                                                at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:480)
                                                                                at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138)
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
                                                                                at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229)
                                                                                at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284)
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030)
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemVisibleChanged(MenuBuilder.java:1065)
                                                                                at android.support.v7.view.menu.MenuItemImpl.setVisible(MenuItemImpl.java:528)
                                                                                at com.example.com.MainActivity.showOption(MainActivity.java:882)
                                                                                at com.example.com.MainActivity.activarConfigHorarios(MainActivity.java:1035)
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:652)
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:555)
                                                                                at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:116)
                                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                             Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.view.menu.ActionMenuItemView
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:480) 
                                                                                at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229) 
                                                                                at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284) 
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030) 
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemVisibleChanged(MenuBuilder.java:1065) 
                                                                                at android.support.v7.view.menu.MenuItemImpl.setVisible(MenuItemImpl.java:528) 
                                                                                at com.example.com.MainActivity.showOption(MainActivity.java:882) 
                                                                                at com.example.com.MainActivity.activarConfigHorarios(MainActivity.java:1035) 
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:652) 
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:555) 
                                                                                at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:116) 
                                                                                at android.os.Handler.handleCallback(Handler.java:739) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                             Caused by: java.lang.reflect.InvocationTargetException
                                                                                at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:480) 
                                                                                at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229) 
                                                                                at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284) 
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030) 
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemVisibleChanged(MenuBuilder.java:1065) 
                                                                                at android.support.v7.view.menu.MenuItemImpl.setVisible(MenuItemImpl.java:528) 
                                                                                at com.example.com.MainActivity.showOption(MainActivity.java:882) 
                                                                                at com.example.com.MainActivity.activarConfigHorarios(MainActivity.java:1035) 
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:652) 
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:555) 
                                                                                at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:116) 
                                                                                at android.os.Handler.handleCallback(Handler.java:739) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                             Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f010049 a=-1}
                                                                                at android.content.res.TypedArray.getColorStateList(TypedArray.java:482)
                                                                                at android.widget.TextView.<init>(TextView.java:1043)
                                                                                at android.widget.TextView.<init>(TextView.java:671)
                                                                                at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
                                                                                at android.support.v7.view.menu.ActionMenuItemView.<init>(ActionMenuItemView.java:72)
                                                                                at android.support.v7.view.menu.ActionMenuItemView.<init>(ActionMenuItemView.java:68)
                                                                                at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                                at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.createItemView(BaseMenuPresenter.java:161) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:180) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:192) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:480) 
                                                                                at android.support.v7.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1138) 
                                                                                at android.support.v7.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91) 
                                                                                at android.support.v7.widget.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:229) 
                                                                                at android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:284) 
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1030) 
                                                                                at android.support.v7.view.menu.MenuBuilder.onItemVisibleChanged(MenuBuilder.java:1065) 
                                                                                at android.support.v7.view.menu.MenuItemImpl.setVisible(MenuItemImpl.java:528) 
                                                                                at com.example.com.MainActivity.showOption(MainActivity.java:882) 
                                                                                at com.example.com.MainActivity.activarConfigHorarios(MainActivity.java:1035) 
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:652) 
                                                                                at com.example.com.DetalleFragment$4.done(DetalleFragment.java:555) 
                                                                                at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:116) 
                                                                                at android.os.Handler.handleCallback(Handler.java:739) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

在我的Java类中(在崩溃的行)我将MenuItem的可见性设置为true或false。

这是一个模型菜单类。:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.com.CalendarActivity"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/action_settings" android:title="@string/action_settings"
        android:orderInCategory="100" app:showAsAction="ifRoom" />
</menu>

有人可以帮我解决这个错误吗?

如果您需要更多信息或代码,请告诉我

0 个答案:

没有答案