首页 文章

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

提问于
浏览
1

我试图模仿靛蓝粉红色和白色的风格,由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后退按钮的颜色?

感谢您的关注 .
enter image description here

enter image description here

2 回答

  • 0

    使用 android:Theme.Material.Light.DarkActionBar - 这可以优化黑暗的操作栏 - 自动为您提供白色图标和文字 .

  • 1

    你可以尝试这个:

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

相关问题