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

前端 未结 4 1518
清歌不尽
清歌不尽 2020-12-09 10:28

I\'m trying to upgrade my app from API19 to API21

The main changes I\'ve made to the gradle properties are:

compileSdkVersion 21
buildToolsVersion \"         


        
相关标签:
4条回答
  • 2020-12-09 10:34

    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.

    0 讨论(0)
  • 2020-12-09 10:41

    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.

    0 讨论(0)
  • 2020-12-09 10:44

    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.

    0 讨论(0)
  • 2020-12-09 10:46

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

    0 讨论(0)
提交回复
热议问题