gpt4 book ai didi

android - 选择文本时 Android 3.2 上的 UnsupportedOperationException (AppCompat 21.0.3)

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:45 26 4
gpt4 key购买 nike

我正准备在更新到 AppCompat 21.0.3 后发布我的应用程序。在各种模拟器上进行测试时,我发现每当我尝试在我的 WebView 中选择文本时,Android 3.2 都会发生崩溃。

这在 2.3.3 或 4.0.3 模拟器上似乎没有发生(在 2.3.3 上它选择文本,并允许我触摸复制。在 4.0.3 上它显示 Action 模式,这也是我预计在 3.2)。有没有人遇到过类似的事情?是否有任何修复,还是我们必须等待 AppCompat 更新?

E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsupportedOperationException
at android.support.v7.internal.view.menu.MenuWrapperFactory.wrapSupportMenu(MenuWrapperFactory.java:39)
at android.support.v7.internal.view.SupportActionModeWrapper$CallbackWrapper.getMenuWrapper(SupportActionModeWrapper.java:179)
at android.support.v7.internal.view.SupportActionModeWrapper$CallbackWrapper.onCreateActionMode(SupportActionModeWrapper.java:154)
at android.support.v7.app.ActionBarActivityDelegateBase$ActionModeCallbackWrapper.onCreateActionMode(ActionBarActivityDelegateBase.java:1297)
at android.support.v7.app.ActionBarActivityDelegateBase.startSupportActionModeFromWindow(ActionBarActivityDelegateBase.java:648)
at android.support.v7.app.ActionBarActivityDelegate$1.startActionMode(ActionBarActivityDelegate.java:99)
at android.support.v7.widget.WindowCallbackWrapper.startActionMode(WindowCallbackWrapper.java:69)
at android.support.v7.internal.app.ToolbarActionBar.startActionMode(ToolbarActionBar.java:206)
at android.support.v7.app.ActionBarActivityDelegateBase.startSupportActionMode(ActionBarActivityDelegateBase.java:581)
at android.support.v7.app.ActionBarActivityDelegateHC.startActionModeForChild(ActionBarActivityDelegateHC.java:62)
at android.support.v7.internal.widget.NativeActionModeAwareLayout.startActionModeForChild(NativeActionModeAwareLayout.java:44)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:553)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:553)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:553)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:553)
at android.view.View.startActionMode(View.java:3157)
at android.webkit.WebView.setUpSelect(WebView.java:4935)
at android.webkit.WebView.selectText(WebView.java:3957)
at android.webkit.WebView.selectText(WebView.java:3950)
at android.webkit.WebView.performLongClick(WebView.java:3939)
at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:7752)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)

当我尝试从工具栏的搜索 View 中选择文本时,同样的事情发生了。

E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsupportedOperationException
at android.support.v7.internal.view.menu.MenuWrapperFactory.wrapSupportMenu(MenuWrapperFactory.java:39)
at android.support.v7.internal.view.SupportActionModeWrapper$CallbackWrapper.getMenuWrapper(SupportActionModeWrapper.java:179)
at android.support.v7.internal.view.SupportActionModeWrapper$CallbackWrapper.onCreateActionMode(SupportActionModeWrapper.java:154)
...
at android.view.View.startActionMode(View.java:3157)
at android.widget.TextView.startSelectionActionMode(TextView.java:8306)
at android.widget.TextView.performLongClick(TextView.java:8206)
at android.view.View$CheckForLongPress.run(View.java:11910)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)

编辑:仍在 AppCompat v22 中发生。我目前的解决方案是简单地禁用为受影响的人选择文本,如下所示:

// There is a bug in Android 3.0-3.2 that causes selecting text to crash.
// Temporary fix is to disable long-click/text-selection for API 11-13.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2) {
myWebView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
myWebView.setLongClickable(false);
}

最佳答案

这在支持库 22.1.0 中已修复(请参阅:https://code.google.com/p/android/issues/detail?id=80434)

关于android - 选择文本时 Android 3.2 上的 UnsupportedOperationException (AppCompat 21.0.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27625994/

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