[英]Why does Theme.AppCompat.NoActionBar not hide the action bar while android:Theme.Material.NoActionBar does
[英]Action bar is showing when using NoActionBar theme
我正在使用带有 NoActionBar 的主题。 清单文件:
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
我正在使用另一个操作栏,我将其包含在布局中:
<include layout="@layout/toolbar" />
然而,我总是得到两个工具栏,上面的一个是一个,如果我不使用 NoActionBar 主题就会在那里。 我发现,如果我删除 style.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
) 的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.