gpt4 book ai didi

android - 剪贴板管理器未打开 EditText、WebView 的长按事件

转载 作者:行者123 更新时间:2023-11-29 01:40:10 29 4
gpt4 key购买 nike

在我的一个应用程序中,我实现了 WebView 以从 url 加载一些数据。一切都很完美。

但是每当我尝试长按并选择 WebView 的文本时,应用程序就会崩溃并抛出如下错误:每当我尝试从 EditText onLongPress 事件中选择文本时,它甚至会抛出错误。

我只是不明白为什么会抛出这种错误。

08-05 18:54:13.413: E/AndroidRuntime(29849): FATAL EXCEPTION: main
08-05 18:54:13.413: E/AndroidRuntime(29849): java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)
08-05 18:54:13.413: E/AndroidRuntime(29849): at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:397)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1433)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureVertical(LinearLayout.java:720)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.onMeasure(LinearLayout.java:593)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
08-05 18:54:13.413: E/AndroidRuntime(29849): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2200)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1433)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureVertical(LinearLayout.java:720)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.onMeasure(LinearLayout.java:593)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
08-05 18:54:13.413: E/AndroidRuntime(29849): at com.ovte.slidemenu.widget.Phone_AnimationLayout.onMeasure(Phone_AnimationLayout.java:87)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1433)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureVertical(LinearLayout.java:720)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.onMeasure(LinearLayout.java:593)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1433)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.measureVertical(LinearLayout.java:720)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.LinearLayout.onMeasure(LinearLayout.java:593)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4936)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
08-05 18:54:13.413: E/AndroidRuntime(29849): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2200)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.View.measure(View.java:15679)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2214)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1298)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1492)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1188)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4986)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.Choreographer.doCallbacks(Choreographer.java:579)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.Choreographer.doFrame(Choreographer.java:548)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.os.Handler.handleCallback(Handler.java:725)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.os.Handler.dispatchMessage(Handler.java:92)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.os.Looper.loop(Looper.java:153)
08-05 18:54:13.413: E/AndroidRuntime(29849): at android.app.ActivityThread.main(ActivityThread.java:5316)
08-05 18:54:13.413: E/AndroidRuntime(29849): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 18:54:13.413: E/AndroidRuntime(29849): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 18:54:13.413: E/AndroidRuntime(29849): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-05 18:54:13.413: E/AndroidRuntime(29849): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-05 18:54:13.413: E/AndroidRuntime(29849): at dalvik.system.NativeStart.main(Native Method)

我已经尝试过以下网站的建议:

Illegal State exception on double clicking a edittext

http://code.google.com/p/android/issues/detail?id=19021

How to avoid a IllegalStateException: ActionBarContextView in older app

How to avoid a IllegalStateException: ActionBarContextView in older app

任何人都可以给我这个错误的解决方案。

谢谢。

最佳答案

最后我找到了一个解决方案,我限制了复制的文本,使用 setCustomSelectionActionModeCallback() 方法粘贴,如下所示:

edittext.setCustomSelectionActionModeCallback(new Callback() {

public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}

public void onDestroyActionMode(ActionMode mode) {
}

public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}

public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});

onCreateActionMode(ActionMode, Menu) 返回 false 将阻止启动操作模式(全选、剪切、复制和粘贴操作)。

关于android - 剪贴板管理器未打开 EditText、WebView 的长按事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25203506/

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