怎样才可以有一个阴影在我的动作条(ActionBarSherlock)? [英] How can I have a drop shadow on my ActionBar (ActionBarSherlock)?

查看:110
本文介绍了怎样才可以有一个阴影在我的动作条(ActionBarSherlock)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我包括我的风格的XML布局:

I am including my styled xml layout:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Styled" parent="Theme.Sherlock">
        <item name="actionBarStyle">@style/Widget.MyApp.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.MyApp.ActionBar</item>

    </style>

    <style name="Widget.MyApp.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
        <item name="titleTextStyle">@style/Widget.MyApp.TitleTextStyle</item>
        <item name="background">@color/red</item>
        <item name="android:background">@color/red</item>
        <item name="windowContentOverlay">@null</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

    <style name="Widget.MyApp.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">21sp</item>
    </style>

</resources>

某些搜索互联网上的建议,使用windowContentOverlay设置为@null。但是,当我用它在风格上的XML它不会改变任何事情。任何一个可以帮助该怎么办?

Some of the search over internet suggests that use windowContentOverlay set to @null. But when i use it in the style xml it doesn't change anything. Can any one help what to do?

推荐答案

如果你想创建下面的动作条阴影,你必须设置安卓上的windowContentOverlay 参数应用主题(在code您没有正确设置它的动作条的风格)。

If you want to create a shadow below the ActionBar you have to set android:windowContentOverlay parameter on the application theme (in your code you are incorrectly setting it on the ActionBar style).

在你的榜样,这将是:

<style name="Theme.Styled" parent="Theme.Sherlock">
        ...
        <item name="android:windowContentOverlay">@drawable/my_actionbar_shadow</item>
</style>

使用 @null 值删除影子。

这一条线设置在Android 3.0和较新的动作条上的阴影。然而,如果你使用的是ActionBarSherlock,它不会像您期望的工作。这会造成在窗口顶部的阴影中运行系统较旧的Andr​​oid设备的ActionBarSherlock比Android 4.0(虽然动作条为present在由于Android 3.0的API,ActionBarSherlock使用自定义实现所有的Andr​​oid版本早于Android 4.0的)

This one line sets the shadow on ActionBar on Android 3.0 and newer. However if you are using ActionBarSherlock, it will not work as you expect. It would create the shadow on top of the window over the ActionBarSherlock on Android devices running system older than Android 4.0 (although ActionBar is present in the api since Android 3.0, ActionBarSherlock uses custom implementation for all Android versions older than Android 4.0).

要创建下面ActionBarSherlock的影子,你必须在应用程序的主题设置 windowContentOverlay 参数(注意缺少机器人:

To create the shadow below ActionBarSherlock you have to set windowContentOverlay parameter on the application theme (notice the missing android:).

<style name="Theme.Styled" parent="Theme.Sherlock">
        ...
        <item name="windowContentOverlay">@drawable/my_actionbar_shadow</item>
</style>

再次使用 @null 删除影子。

虽然这条线适用于ActionBarSherlock,它不运行Android 4.0及更高版本的Andr​​oid设备的工作,没有阴影下的动作条在这些设备上创建的。因此,如何这两个参数结合起来,让双方在动作条和ActionBarSherlock所需的影子?

Although this line works for ActionBarSherlock, it doesn't work on android devices running Android 4.0 and newer, no shadow is created under the ActionBar on such devices. So how to combine these two parameters to get the desired shadow under both ActionBar and ActionBarSherlock?

使用<一个href="http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources">resource配置预选赛的,你的情况使用的平台版本预选赛。 在 RES /价值/ styles.xml 使用第二个XML code。而在 RES /值-V14 / styles.xml 使用的第一个XML code。因此,ActionBarSherlock版本默认情况下使用(对于版本pre的Andr​​oid 4.0)和动作条版本用于安卓4.0及更高版本。

Use resource configuration qualifiers, in your case use platform version qualifiers. In res/values/styles.xml use the second xml code. And in res/values-v14/styles.xml use the first xml code. Therefore the ActionBarSherlock version is used by default (for versions pre Android 4.0) and ActionBar version is used for Android 4.0 and newer.

编辑: 有一个在安卓4.3 错误(API级别18),安卓windowContentOverlay 不起作用。它应固定在未来的版本。如果你需要它固定在Android的4.3,你可以找到解决方法的错误报告链接。

There is a bug in Android 4.3 (API level 18), android:windowContentOverlay does not work. It should be fixed in future release. In case you need it fixed in Android 4.3, you can find workarounds linked in the bug report.

这篇关于怎样才可以有一个阴影在我的动作条(ActionBarSherlock)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆