如何通过样式自定义操作栏上的后退按钮

How to customize the back button on action bar via styling

我正在尝试模仿 Google here 指定的靛粉色和白色风格。

如果我选择父主题android:Theme.Material,那么背景会是深色的,文字会是白色的。这导致我选择父应用主题为 android:Theme.Material.Light

但是,现在 ActionBar 中的项目是黑色的。我能够通过

将文本颜色设置回白色
<style name="AppTheme" parent="android:Theme.Material.Light">
    ...
    <item name="android:actionBarStyle">@style/AppTheme.MyActionBar</item>
    ...
</style>

<style name="AppTheme.MyActionBar" parent="@android:style/Widget.Material.ActionBar">
    ...
    <item name="android:titleTextStyle">@style/AppTheme.MyActionBar.TitleTextStyle</item>
    ...
</style>

<style name="AppTheme.MyActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Material.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

现在我需要覆盖后退按钮的颜色。

不幸的是,将 MyActionBar 样式的父级指定为 @android:style/Widget.Material.ActionBar(而不是 @android:style/Widget.Material.Light.ActionBar)无法完成这项工作。

这个讨论How to customize the back button on ActionBar 讲述了如何通过@drawable 指定资源。然而,我想使用类似于样式文本的方法使用深色主题中的后退按钮。

是否可以通过某种方式继承预先存在的样式来更改 ActionBar 后退按钮的颜色?

感谢您的关注。

你可以试试这个:

<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
    <item name="android:homeAsUpIndicator">@drawable/my_fancy_up_indicator</item>
</style>

使用 android:Theme.Material.Light.DarkActionBar - 这针对深色操作栏进行了优化 - 自动为您提供白色图标和文本。