【发布时间】:2021-08-04 06:10:21
【问题描述】:
在 Jetpack Compose 中,TopAppBar 显示 default background color,无论我们添加到 themes.xml 的内容如何。
那么我们如何才能将 TopAppBar 背景颜色从 themes.xml 更改为全局应用于应用程序。
TopAppBar(
title = { Text("Activity") },
navigationIcon = {
IconButton(onClick = { onBackPressed() }) {
Icon(Icons.Filled.ArrowBack, contentDescription = null)
}
}
)
主题.xml
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight">
<!-- Primary brand color. -->
<item name="colorPrimary">@android:color/black</item>
<item name="colorPrimaryVariant">@android:color/holo_orange_dark</item>
<item name="colorOnPrimary">@android:color/white</item>
</style>
注意:我们可以通过TopAppBar的backgroundColor属性来改变它,但这里我想全局实现它。
【问题讨论】:
-
检查this
标签: android android-jetpack-compose