事情是这样的:在我的 Styles.xml 中,我有一个通用样式,并且一个样式继承了另一个样式,如下所示:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="@style/AppTheme">
<item name="colorPrimary">#0acf66</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
当我应用第二个主题(AppTheme.NoActionBar)时,它继承了颜色,但操作栏仍然存在。如果我将第二个样式的父级更改为 Theme.AppCompat.NoActionBar 它可以工作,但颜色完全不同。我该如何修复它?
所以这是样式/它们的继承问题。有两种方法可以从样式继承属性。
1.通过点表示法(隐式):
<style name="Theme.AppCompat.NoActionBar.Custom">
// the parent will be Theme.AppCompat.NoActionBar
</style>
2.通过父标签(显式)
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
//the parent is Theme.AppCompat.Light.DarkActionBar
</style>
要永远记住一件事,显式继承胜过隐式继承。
所以在你的情况下
<style name="AppTheme.NoActionBar" parent="@style/AppTheme">
// your parent is AppTheme, and new style is AppThem.NoActionBar,
but it doesn't inherit from an actual NoActionBar style.
</style>
为了拥有“NoActionBar”主题,实际上您必须从具有该属性的样式继承。所以你可以创建另一个AppTheme.NoActionBar
继承自Theme.AppCompat.NoActionBar
.
为了更好地了解主题/风格,请检查这个很棒的内容2016 年谷歌 I/O 大会有关样式和主题的链接。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)