更新时间:2023-01-27 17:35:16
使用材质主题,您可以使用不同的选项来自定义工具栏
Using a material theme you have different options to customize the text color used in the Toolbar
android:theme
覆盖仅用于 Toolbar
android:theme
to override default values only for your Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:theme="@style/MyThemeOverlay_Toolbar"
...>
并使用:
<style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
<!-- color used by the toolbar title -->
<item name="android:textColorPrimary">@color/secondaryColor</item>
<!-- color used by navigation icon and overflow icon -->
<item name="colorOnPrimary">@color/secondaryColor</item>
</style>
工具栏
<com.google.android.material.appbar.MaterialToolbar
style="@style/MyToolbar"
.../>
然后使用 materialThemeOverlay
覆盖默认值(它需要材料组件库版本1.1.0):
And then use the materialThemeOverlay
to override the default values (it requires the material components library version 1.1.0):
<!-- Toolbar -->
<style name="MyToolbar" parent="Widget.MaterialComponents.Toolbar">
<item name="materialThemeOverlay">@style/MyThemeOverlay_Toolbar</item>
</style>
<style name="MyThemeOverlay_Toolbar" parent="">
<item name="android:textColorPrimary">@color/secondaryColor</item>
<item name="colorOnPrimary">@color/secondaryColor</item>
</style>