1

I set a background image to my actionbar wich has a wood texture and a drop shadow with transparency at the bottom, the problem is that the views inside of my actionbar are vertical aligned at middle so they look like they are "out" of the actionbar. I wonder if there is a way to place those views on top of the actionbar (I already tried to change the gravity and paddingTop but I still don't get it to work).

This is what I'd tried without success:

<style name="UniversiaTheme" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:actionBarSize">68dp</item> 
    <item name="android:windowBackground">@drawable/background</item>
</style>

<style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:layout_gravity">top</item>
    <item name="android:gravity">top</item>
    <item name="android:background">@drawable/ab_background</item>
    <item name="android:titleTextStyle">@style/ActionBar.TitleTextStyle</item>
</style>

<style name="ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/brown</item>
    <item name="android:textSize">@dimen/titleSize_default</item>
</style>

And here is an screenshot image of how my actionbar looks like:

enter image description here

EDIT: Maybe this image will help to explain the issue a little bit better. Notice the background image which has a transparency and only covers the half of the actionbar space. (That's why I what to place the views that are inside of the actionbar on top, not on the middle of the actionbar)

enter image description here

Thank you in advance, I would appreciate any help.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
didi3r
  • 227
  • 1
  • 3
  • 11
  • 1
    Is the wood texture background a 9-patch image? – Siddharth Lele Mar 25 '13 at 02:57
  • @SiddharthLele No, it's just a PNG image. – didi3r Mar 25 '13 at 03:16
  • 1
    Can you try changing the `68dp` to _48dp_? That is the recommended default [Source](http://developer.android.com/design/style/metrics-grids.html#examples) – Siddharth Lele Mar 25 '13 at 04:11
  • The thing is that I intentionally change de size of the actionBar because background has a transparency and it only covers the half of the actionbar space ...I have added a new image ilustrating this. Thanks! – didi3r Mar 25 '13 at 05:11
  • It caught my attention that I've met a similar issues with you, but mine is the items in ActionBar seemed aligned to top even I set it to center aligned. http://stackoverflow.com/questions/15554487/button-in-actionbarsherlock-not-vertically-centered and I haven't got it resolved. – dumbfingers Mar 25 '13 at 17:05
  • @didi3r may i ask that, what's your root layout in the layout file you've pasted above? `RelativeLayout` or `LinearLayout` or something else? – dumbfingers Mar 26 '13 at 09:28
  • @didi3r I've solved my problem via different ways, could you try mine and let me know if it works? http://stackoverflow.com/a/15636929/763459 cheers – dumbfingers Mar 26 '13 at 12:20
  • @ss1271 I don't have a custom layout for my actionbar, Im just working with the default android actionbar and I've changed its appearance with the above styles. – didi3r Mar 26 '13 at 20:41

1 Answers1

3

Try playing around with the setting for "android:layout_marginBottom" or "android:paddingBottom" instead of gravity in your ActionBar style. I was playing around with a sample project and it looks like that will work. Something between 10-20dp should do the trick.

Matt Wolfe
  • 8,924
  • 8
  • 60
  • 77
  • but will it get messed up when running the app on devices with different resolutions (the pixels that converted from dp will change if the resolutions are not the same)? – dumbfingers Mar 25 '13 at 17:16
  • Yeah! You where rigth, I set a 22dp android:paddingBottom and a -15dp android:layout_marginBottom, and now the views are in the middle of the wood texture. Thank you very much! – didi3r Mar 26 '13 at 00:03
  • @ss1271 As far as I know dp is a relative measure that is proportional to the screen resolution, and since the actionbar has a dp size too it will scale depending on screen resolution... am I right? – didi3r Mar 26 '13 at 00:09
  • @didi3r cool, I got it and thx. That could be a workaround for my question. – dumbfingers Mar 26 '13 at 00:59