在我的一个应用程序中,我实现了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
任何人都可以为我提供此错误的解决方案。
谢谢。
答案 0 :(得分:1)
最后我找到了一个解决方案,我限制了正在复制的文本,使用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将阻止启动操作模式(选择全部,剪切,复制和粘贴操作)。