ICS上的支持库v21不支持ActionMode?

时间:2014-10-27 18:40:57

标签: android android-support-library

我正在开发一个使用ActionMode的应用。

项目依赖项:

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.+'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:support-v13:21.0+'
}

API级别:

minSdkVersion 14
targetSdkVersion 21

我的片段使用ActionMode

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    mode.getMenuInflater().inflate(R.menu.packing_list_context, menu);
    return true;
}
...

菜单:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/context_menu_item_edit"
        android:icon="@drawable/ic_edit_black_24dp"
        app:showAsAction="always"
        android:title="@string/context_menu_item_edit" />

    <item
        android:id="@+id/context_menu_item_delete"
        android:icon="@drawable/ic_delete_black_24dp"
        app:showAsAction="always"
        android:title="@string/context_menu_item_delete" />

    <item
        android:id="@+id/context_menu_item_tags"
        android:icon="@drawable/ic_label_black_24dp"
        app:showAsAction="always"
        android:title="@string/context_menu_item_tags" />
</menu>

当我在Android 4.4上运行此应用程序时,一切都很好。但是当我在Android 4.0.3上运行它时,我在支持库的某个地方收到以下异常:

堆栈追踪:

W/System.err( 7292): java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.getActionProvider()
W/System.err( 7292): at android.support.v7.internal.view.menu.MenuItemImpl.getActionProvider(MenuItemImpl.java:634)
W/System.err( 7292): at android.support.v7.internal.view.menu.MenuItemWrapperICS.getSupportActionProvider(MenuItemWrapperICS.java:322)
W/System.err( 7292): at android.support.v7.internal.view.menu.MenuItemWrapperICS.checkActionProviderOverrideVisibility(MenuItemWrapperICS.java:348)
W/System.err( 7292): at android.support.v7.internal.view.menu.MenuItemWrapperICS.setVisible(MenuItemWrapperICS.java:183)
W/System.err( 7292): at android.support.v7.internal.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:425)
W/System.err( 7292): at android.support.v7.internal.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:479)
W/System.err( 7292): at android.support.v7.internal.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:196)
W/System.err( 7292): at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)
W/System.err( 7292): at net.cornplay.tourist.fragments.PackingListFragment.onCreateActionMode(PackingListFragment.java:392)
W/System.err( 7292): at android.widget.AbsListView$MultiChoiceModeWrapper.onCreateActionMode(AbsListView.java:5635)
W/System.err( 7292): at android.support.v7.internal.view.SupportActionModeWrapper$CallbackWrapper.onCreateActionMode(SupportActionModeWrapper.java:151)
W/System.err( 7292): at android.support.v7.app.ActionBarActivityDelegateBase$ActionModeCallbackWrapper.onCreateActionMode(ActionBarActivityDelegateBase.java:1367)
W/System.err( 7292): at android.support.v7.internal.app.WindowDecorActionBar$ActionModeImpl.dispatchOnCreate(WindowDecorActionBar.java:1012)
W/System.err( 7292): at android.support.v7.internal.app.WindowDecorActionBar.startActionMode(WindowDecorActionBar.java:510)
W/System.err( 7292): at android.support.v7.app.ActionBarActivityDelegateBase.startSupportActionMode(ActionBarActivityDelegateBase.java:576)
W/System.err( 7292): at android.support.v7.app.ActionBarActivityDelegateHC.startActionModeForChild(ActionBarActivityDelegateHC.java:62)
W/System.err( 7292): at android.support.v7.internal.widget.NativeActionModeAwareLayout.startActionModeForChild(NativeActionModeAwareLayout.java:44)
W/System.err( 7292): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
W/System.err( 7292): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
W/System.err( 7292): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
W/System.err( 7292): at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:571)
W/System.err( 7292): at android.view.View.startActionMode(View.java:3607)
W/System.err( 7292): at android.widget.AbsListView.setItemChecked(AbsListView.java:952)
W/System.err( 7292): at net.cornplay.tourist.fragments.PackingListFragment.onItemLongClick(PackingListFragment.java:350)
W/System.err( 7292): at net.cornplay.tourist.adapters.PackingListAdapter$2.onLongClick(PackingListAdapter.java:87)
W/System.err( 7292): at android.view.View.performLongClick(View.java:3547)
W/System.err( 7292): at android.view.View$CheckForLongPress.run(View.java:14088)
W/System.err( 7292): at android.os.Handler.handleCallback(Handler.java:605)
W/System.err( 7292): at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err( 7292): at android.os.Looper.loop(Looper.java:137)
W/System.err( 7292): at android.app.ActivityThread.main(ActivityThread.java:4424)
W/System.err( 7292): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 7292): at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err( 7292): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
W/System.err( 7292): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
W/System.err( 7292): at dalvik.system.NativeStart.main(Native Method)

Google暗示了这些问题:https://code.google.com/p/android/issues/detail?id=77724https://code.google.com/p/android/issues/detail?id=78212。但它们如何与我的代码相关?我不使用ShareActionProvider

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

实际上,这是AppCompat库中的一个错误。它已在v21.0.2中修复。刚升级,应用程序不再崩溃。