Add a shadow on ActionBar

元气小坏坏 提交于 2019-12-30 11:04:40

问题


I am trying to add a shadow under the title of the ActionBar. I have tried putting the attributes

    <item name="android:textColor">@color/white</item>
    <item name="android:shadowRadius">1</item>
    <item name="android:shadowColor">@color/black</item>
    <item name="android:shadowDy">1</item>

but while textColor is working, the shadow isn't. I am using ActionBarSherlock 3.5 but I think it would not work on native either.

Thanks


回答1:


I can't get this to work either on native or ABS backport. Using the approach mentioned here works great. For the android:customNavigationLayout layout you can just supple a single textView with your style applied. This has the drawback of having to set the title programatically in your activity / base activity. This can be done by grabbing the value from Activity.getTitle(), which is what the action bar does if a title is set. Not enough time to look into further!

ps Hi Chris!




回答2:


I haven't tried on native, but as Jake mentions, if it doesn't work on native, he wont support it in ABS.

If you really did want to override it, and this would ONLY work on pre 3.2 (or 4.0 with ABS 4.X) Then you can grab the res/layout/abs__action_bar_title_item.xml put it in your project and change the:

<com.actionbarsherlock.internal.widget.ScrollingTextView
        android:id="@+id/abs__action_bar_title"
        ...
        android:shadowRadius="1"
        ... />

Of course I do not recommend this! As it will NOT work on native implementations.




回答3:


Adding a shadow under the title of the (native) ActionBar works starting with API Level 18 (Android Jelly Bean 4.3). Works fine in API Level 19 (Android KitKat 4.4).

Tested with simulators and native devices starting with API Level 15 (Android Ice Cream Sandwich 4.0.3 - 4.0.4).

<!-- Settings activity theme -->
<style name="AppSettingsTheme" parent="android:Theme.Holo.Light">
    <!-- Set the action bar custom style -->
    <item name="android:actionBarStyle">@style/AppActionBar</item>
</style>

<!-- Action bar style -->
<style name="AppActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:titleTextStyle">@style/AppActionBarTitleText</item>
    <item name="android:displayOptions">showTitle</item>
</style>

<!-- ActionBar title text -->
<style name="AppActionBarTitleText"
    parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white_text</item>
    <item name="android:shadowColor">@color/text_shadow</item>
    <item name="android:shadowDx">3</item>
    <item name="android:shadowDy">3</item>
    <item name="android:shadowRadius">1.5</item>
</style>

This is a screenshot from an API 18 emulator:



来源:https://stackoverflow.com/questions/9698414/add-a-shadow-on-actionbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!