Upgrading to SDK 21 - Error inflating class android.support.v7.internal.widget.ActionBarContainer

风流意气都作罢 提交于 2019-11-28 08:24:01
nibarius

I had the same problem when trying to use ?attr/selectableItemBackground and based on your answer and some digging around on the internet I found out what was wrong for me (and probably you as well).

From this answer I learned that "? mark is used to reference style in current theme." Which means that when you use ?attr/ you refer to something in the current theme.

I noticed that I got this crash only when inflating using the application context and not when using the activity context. This blog post explains what's happening in "Context Capabilities" section.

...[When using the application context] inflation will be done with the default theme for the system on which you are running, not what’s defined in your application.

This mean that ?attr/ won't work since they refer to the current theme, not the default system theme you're inflating with.

So ?attr/ works fine if you make sure to inflate using the Activity context instead of the application context.

I had similar issue, i'm using AppCompat.v21 and supporting Android 5.0.

My layout uses the ?attr/[attribute_name] for some values and I use the activity context.

I changed it to ?android:attr/[attribute_name] and now my views inflate just fine on devices running Android 5.0.

For me the issue seemed to be in layout files when using the ?attr/ format for values. I'm not sure if it's theme related. I took all these out to get things going and then added styles back in.

style name="AppTheme" parent="Base.V23.Theme.AppCompat" in style.xml worked for my app.

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