我正在開發一個應用程序,我使用ActionMode
。ICS上的支持庫v21不支持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)
谷歌暗示這些問題:https://code.google.com/p/android/issues/detail?id=77724,https://code.google.com/p/android/issues/detail?id=78212。但是他們怎麼可能與我的代碼相關?我不使用ShareActionProvider
。
任何想法?
我在Android L Preview跟蹤器上發現了類似的問題:https://code.google.com/p/android-developer-preview/issues/detail?id=1660。 – 2014-10-27 19:26:11
嘿,我得到了一個非常類似我的應用程序的崩潰報告。你解決了這個問題嗎?你可以在你的4.0.x設備上試用它來驗證它是同一個問題嗎?以下是我的應用:https://play.google.com/store/apps/details?id = com.lb.app_manager。爲了激活操作模式,可以長按一個項目或單擊一個圖標。事情是,我不使用getActionProvider或者甚至是一個ShareActionProvider。我只是使用「startSupportActionMode」... – 2014-11-29 15:58:43
@androiddeveloper我在4.0.3上檢查了你的應用程序 - 它不會崩潰。 – 2014-12-04 15:30:15