java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="

来源:互联网 发布:手机解压软件 编辑:程序博客网 时间:2024/05/18 02:05
- Steps to reproduce the problem (including sample code if appropriate).Implement a Dialog(Maybe an Activity also has this issue. But I have not tested it.) using a customized theme which does not extends any of a Android basic theme. Such as:    <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>Also add a EditText into the dialog layout.Run the dialog on a Tablet(I used Galaxy Tab 10.1 with Android OS 3.1). Type some words into the EditText. Then double click the typed words.- What happened.Crashed with this exception message: java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)  at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:257)  at android.view.View.measure(View.java:10840)  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)  at android.widget.LinearLayout.measureVertical(LinearLayout.java:613)  at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)  at android.view.View.measure(View.java:10840)  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4351)  at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2042)  at android.view.View.measure(View.java:10840)  at android.view.ViewRoot.performTraversals(ViewRoot.java:884)  at android.view.ViewRoot.handleMessage(ViewRoot.java:2017)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:132)  at android.app.ActivityThread.main(ActivityThread.java:4028)  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:844)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)  at dalvik.system.NativeStart.main(Native Method)- What you think the correct behavior should be.It should not crash and show OS selection UI to allow user to select words.It works before OS 3.0. So it is a backward compatibility issue.If it really need to throw a exception, at least we should get some information about why it happened more clearly.
Comment 1 by mr.polar...@gmail.comAug 3, 2011
If I modify the style as below. It will not crash.<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></style>
原创粉丝点击