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

前端 未结 4 1530
清歌不尽
清歌不尽 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: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.

提交回复
热议问题