问题
最近使用了Support Design包
通过compile 'com.android.support:design:24.2.1'添加依赖
需要使用一个TabLayout,但是使用过程中一直是不能加载布局文件。
android.view.InflateException: Binary XML file line #11: Error inflating class android.support.design.widget.TabLayout
解决方案
网络上找到了很多,大都是说style定义需要更改
在res/values中的styles.xml中,需要修改parent的属性值,不能使用自定义的。
这里面有两个styles.xml都需要修改
修改内容,参考如下:
<resources>
<style name="AppTheme" parent="Base.AppTheme">
<!-- Customize your theme here. -->
</style>
<!-- Base application theme. -->
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#FF4081</item>
</style>
</resources>
修改parent中的属性值,与上面定义的对应
<resources>
<style name="AppTheme" parent="Base.AppTheme">
</style>
</resources>
参考链接 http://stackoverflow.com/questions/30547323/error-when-using-any-android-design-support-library-elements/30557995#30557995
按照这个方案更改之后,还是报错,
后来想了想,我在项目中inflate布局文件使用的activity一直都是ApplicationContext,或许应该使用Activity试试。
结果没有错误了。