我正在使用NoActionBar主题。清单文件:
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
我正在使用另一个动作栏,它包含在布局中:
<include layout="@layout/toolbar" />
但是,我总是得到两个工具栏,上面一个是工具栏,如果我不使用NoActionBar主题,它就会在那里。我发现,如果我删除了styles.xml文件中的该部分,它将按预期工作-没有第二个操作栏:
<style name="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
当然,我想将其保留在style.xml文件中,因为这也有助于设置通知面板的颜色。
在我看来,这失败了,因为Theme.MaterialComponents.Light.NoActionBar
是现有主题,并且您正在styles.xml中创建它,因此它会覆盖现有主题。
[我要做的是创建一个新主题,将我要编辑的主题设置为parent
主题:
<style name="AppNoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
然后在清单上设置这个新主题:
android:theme="@style/AppNoActionBar"
这样,您将拥有带有自定义更新的基本主题(Theme.MaterialComponents.Light.NoActionBar
)的属性。