在我们使用第三方View框架时(如:TabPageIndicator),会定义theme属性,当启动项目时,会发现原有的ApplicationTheme样式没有生效(如:状态栏颜色),回到XML,Android Studio也会提示当前布局存在一些问题,部分提示信息如下:
Missing styles. Is the correct theme chosen for this layout? Use the Theme combo
box above the layout to choose a different layout, or fix the theme style
references. Failed to find style 'vpiTabPageIndicatorStyle' in current theme
java.lang.IllegalStateException: ViewPager has not been bound.
解决方案:
在Manifest内对应的使用单独theme的Activity,我们需要在这个Activity的theme里
android:theme="@style/StyledIndicatorsBGwhite"
点击进入style配置文件,application theme样式如下(个人示例):
<style name="AppTheme.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:screenOrientation">portrait</item>
</style>
而我们要修改的android:theme=”@style/StyledIndicatorsBGwhite”则在style文件内进入如下更改:
//在这个style name 后增加parent属性,值为application theme所对应的样式名,我的是AppTheme.NoActionBar
<style name="StyledIndicatorsBGwhite" parent="@style/AppTheme.NoActionBar">
//item的style为自己需要实现的style配置
<item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicatorBGWhite</item>
</style>