How to avoid a IllegalStateException: ActionBarContextView in older app

点点圈 提交于 2020-01-03 15:35:20

问题


We have an app that's been working for years. So it does NOT use all the latest and greatest features.

We've found that on current versions of Android, IF there is text in an EditText control AND you long-touch it - the app crashes with:

11-13 14:26:20.720: E/AndroidRuntime(1253): FATAL EXCEPTION: main
11-13 14:26:20.720: E/AndroidRuntime(1253): java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="match_parent" (or fill_parent)
11-13 14:26:20.720: E/AndroidRuntime(1253):     at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:325)
11-13 14:26:20.720: E/AndroidRuntime(1253):     at android.view.View.measure(View.java:12603)
11-13 14:26:20.720: E/AndroidRuntime(1253):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
11-13 14:26:20.720: E/AndroidRuntime(1253):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
11-13 14:26:20.720: E/AndroidRuntime(1253):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)

I know that we have no references to an ActionBarContextView anywhere in our xml or java files, nor do we use any Themes. These EditText controls are in Activities, not Dialogs.

We do have a Custom layout as our root layout, and the crash stacktrace does eventually get back to one if it's methods:

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int count = getChildCount();

    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);
      measureChild(child, widthMeasureSpec, heightMeasureSpec);
    }
    setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
  }

Any ideas where to look, or what to change?

来源:https://stackoverflow.com/questions/19966250/how-to-avoid-a-illegalstateexception-actionbarcontextview-in-older-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!