【问题标题】:How to customize the back button on action bar via styling如何通过样式自定义操作栏上的后退按钮
【发布时间】:2015-04-16 21:18:12
【问题描述】:

我正在尝试模仿 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 后退按钮的颜色?

感谢您的关注。

【问题讨论】:

    标签: android


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你可以试试这个:

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

      【讨论】:

      • 谢谢,但正如我所写,我明确试图避免将外部可绘制资源带入项目
      • 所以试着把@drawable/my_fancy_up_indicator改成@color/whatevercolor
      • 它会产生一个带有任何颜色的正方形,这不是我想要的。
      • @user2551017 试试@drawable/abc_ic_ab_back_mtrl_am_alpha,它应该已经在android中可用。所以你不会使用外部资源
      • 因为您正在扩展 theme.material.light,这应该意味着浅色背景,深色前景。哪个是你的后退按钮,溢出菜单按钮应该是黑色的。因此,您需要覆盖它或更改主题的父级
      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 2012-01-03
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      相关资源
      最近更新 更多