双击edittext时出现非法状态异常

时间:2011-06-30 05:52:33

标签: android android-layout android-3.0-honeycomb illegalstateexception

您好,我在双击EditText时遇到非法状态异常。这是堆栈trace.pls帮助

06-30 11:18:24.970: ERROR/AndroidRuntime(3011): java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:257)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.View.measure(View.java:10828)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.View.measure(View.java:10828)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:1890)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.View.measure(View.java:10828)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.ViewRoot.performTraversals(ViewRoot.java:884)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.view.ViewRoot.handleMessage(ViewRoot.java:2003)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.os.Looper.loop(Looper.java:132)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at android.app.ActivityThread.main(ActivityThread.java:4025)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at java.lang.reflect.Method.invokeNative(Native Method)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at java.lang.reflect.Method.invoke(Method.java:491)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-30 11:18:24.970: ERROR/AndroidRuntime(3011):     at dalvik.system.NativeStart.main(Native Method)

4 个答案:

答案 0 :(得分:3)

尝试检查此处提供的解决方案:

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

编辑:

解决方案建议如下:

变化:

<style name="MyDialogTheme">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

对此:

<style name="MyDialogTheme" parent="@android:style/Theme.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:backgroundDimEnabled">false</item>

答案 1 :(得分:0)

如果您阅读第一行,则会显示ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)。换句话说,布局中的某些内容无效android:layout_width。检查......

答案 2 :(得分:0)

我认为问题来自您实施的布局。

我猜你给actionBarContextView一个大小,这是不可能的。您必须为此项目选择 fill_parent match_parent

答案 3 :(得分:0)

下一个例子的结果是:

  • 禁用上下文菜单(双击等),
  • 并防止输入事件对话框崩溃。


editText.setCustomSelectionActionModeCallback(new EditTextNoContextHelper());

public class EditTextNoContextHelper implements ActionMode.Callback { public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } public void onDestroyActionMode(ActionMode mode) { } }