3

嗨,我就雙擊一個EditText上。在這裏得到一個非法狀態例外是堆棧trace.pls幫助非法狀態異常的EditText上

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) 
+2

您可以發佈源代碼? –

回答

0

如果你讀它說ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)的第一道防線。換句話說,你的佈局中的東西有一個無效的android:layout_width。檢查...

0

我認爲問題來自您實施的佈局。

我想你給了你的actionBarContextView的大小,這是不可能的。你必須選擇fill_parentmatch_parent這個項目。

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> 

+0

儘管這可能在理論上回答這個問題,但[這將是更可取的](http://meta.stackexchange.com/q/8259)在這裏包括了答案的基本部分,並提供了供參考的鏈接。 –

+0

當我擁有的是日誌時,如何知道哪種風格是錯誤的? –

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) { } }