<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<!-- 通过 colorPrimary 也可以修改标题栏背景色,但是建议放在 actionBarTheme 中去,免得影响其它控件 -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- You need to set the actionBarTheme attribute (not actionBarStyle) with colorControlNormal. -->
<!-- 通过 actionBarTheme 修改标题栏样式 -->
<item name="actionBarTheme">@style/MyActionBarTheme</item>
</style>
<!-- 参考 https://stackoverflow.com/questions/26788464/how-to-change-color-of-the-back-arrow-in-the-new-material-theme -->
<style name="MyActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorPrimary">#999999</item>
<item name="colorControlNormal">#ff0000</item>
<item name="android:textColorPrimary">#00ff00</item>
<item name="android:textColorSecondary">#ffff00</item>
</style>
</resources>
image.png
当然,也可以使用 ToolBar 来实现,直接在布局 xml 中配置属性即可。









网友评论