Android ActionBarSherlock - 带有分隔线的操作栏自定义背景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10364045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:25:55  来源:igfitidea点击:

ActionBarSherlock - actionbar custom background with divider

androidactionbarsherlock

提问by ikarius

I'm implementing ActionBarsherlockand I want to change the actionbar background.

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

I override the properties but the blue divider dissapear. How can I use custom background with the blue divider?

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

<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>

回答by DanielGrech

For anyone who (like me) doesn't enjoy playing around with 9-patch images, you can get the divider at the bottom of the action bar using an xml drawable:

对于那些(像我一样)不喜欢玩 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>

Save this as drawable/action_bar_background.xml, Then apply it in your theme:

将其保存为 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>

回答by kzotin

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

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

This project can be used to generate ActionBar style you need.

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

回答by Jake Wharton

The blue divider is the background by default. It's a 9-patch drawable which will ensure the line always appears at the bottom of the action bar regardless of its height.

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

For your situation I would copy the default background .pngs from Android and then modify them so that the expandable section of the 9-patch is your target background color. This will fill the action bar with your desired color while maintaining the blue border at the bottom.

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

回答by Jordy

Just an update on the answer provided by DanielGrech. It's also possible to use your own custom graphic at the bottom of the actionbar. Like this:

只是对 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>