gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:12:11 24 4
gpt4 key购买 nike

我正在开发一个使用 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

我的 fragment 使用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=77724 , https://code.google.com/p/android/issues/detail?id=78212 .但是它们怎么会和我的代码相关呢?我不使用 ShareActionProvider

有什么想法吗?

最佳答案

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

关于android - ICS 上的支持库 v21 不支持 ActionMode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26594546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com