【问题标题】:ActionBarSherlock - actionbar custom background with dividerActionBarSherlock - 带有分隔线的操作栏自定义背景
【发布时间】:2012-05-08 23:50:37
【问题描述】:

我正在实施ActionBarsherlock,我想更改操作栏背景。

我覆盖了属性,但蓝色分隔线消失了。如何使用带有蓝色分隔线的自定义背景?

<style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverflow">
    <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
</style>

<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">#ff3e3f3d</item>
    <item name="background">#ff3e3f3d</item>
</style>

【问题讨论】:

    标签: android actionbarsherlock


    【解决方案1】:

    对于(像我一样)不喜欢玩 9-patch 图像的任何人,您可以使用 xml drawable 在操作栏底部获取分隔符:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- Bottom Line -->
        <item>
            <shape android:shape="rectangle">
                <solid android:color="@color/action_bar_line_color" />
            </shape>
        </item>
    
        <!-- Color of your action bar -->
        <item android:bottom="2dip">
            <shape android:shape="rectangle">
                <solid android:color="@color/action_bar_color" />
            </shape>
        </item>
    </layer-list>
    

    将此保存为drawable/action_bar_background.xml,然后将其应用到您的主题中:

    <style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
        <item name="android:background">@drawable/action_bar_background</item>
        <item name="background">@drawable/action_bar_background</item>
    </style>
    

    【讨论】:

    • 这正是我要找的!
    • 这样的东西找了一个星期,真是太好了!
    • 如何将其应用于 Theme.Sherlock.Light?
    • menuItem 的分隔符怎么样?
    • 我在这里做类似的事情!!! stackoverflow.com/questions/19623805/…
    【解决方案2】:

    http://jgilfelt.github.io/android-actionbarstylegenerator/

    这个项目可以用来生成你需要的ActionBar样式。

    【讨论】:

    • 非常感谢,这正是我一直在寻找的东西,让主题变得容易多了!
    • 非常感谢分享。这正是我需要的!
    • 有没有使用教程??我不知道在哪里复制这些图像并设置它们。
    【解决方案3】:

    默认情况下,蓝色分隔线是背景。它是一个 9-patch 可绘制对象,可确保线条始终出现在操作栏的底部,无论其高度如何。

    对于您的情况,我会从 Android 复制默认背景 .pngs,然后对其进行修改,使 9-patch 的可扩展部分成为您的目标背景颜色。这将使用您想要的颜色填充操作栏,同时保持底部的蓝色边框。

    【讨论】:

    • 谢谢,我要复制默认背景,修改一下。
    【解决方案4】:

    只是 DanielGrech 提供的答案的更新。也可以在操作栏底部使用您自己的自定义图形。像这样:

        <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- Bottom Line with custom graphic instead of a solid color-->
        <item android:drawable="@drawable/bar">
              <shape android:shape="rectangle"/>
        </item>
    
        <!-- Color of your action bar -->
        <item android:bottom="2dip">
            <shape android:shape="rectangle">
                <solid android:color="@color/action_bar_color" />
            </shape>
        </item>
    </layer-list>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多