Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set border bottom in action bar?

how can i draw an actionbar bottom border like this :

enter image description here

i try using margin :

<style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:titleTextStyle">@style/TitleTextStyle</item>
        <item name="android:background">#088A29</item>
        <item name="android:backgroundStacked">#088A29</item>
        <item name="android:backgroundSplit">#0B3B0B</item>
        <item name="android:layout_marginBottom">5dp</item>

but the margin is white and i don't understand how change color

thanks!

like image 353
michele buzzoni Avatar asked Dec 03 '22 20:12

michele buzzoni


2 Answers

For me the following solution worked perfectly and smooth.

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:titleTextStyle">@style/TitleTextStyle</item>
    <item name="android:background">@drawable/custom_background_bar</item>
    <item name="android:layout_marginBottom">5dp</item>

And of course I built the custom_background_bar that I saved into drawable forlder.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle" >
      <solid android:color="#ffff0000" />
    </shape>
  </item>
  <item android:top="-3dp" android:right="-3dp" android:left="-3dp">
    <shape>
      <solid android:color="@android:color/transparent" />
      <stroke
          android:width="2dp"
          android:color="#ff00ff00" />
    </shape>
  </item>
</layer-list>

You are free to change #ffff0000 (the background bar color) and #ff00ff00 (the bottom border color) with the values you prefer. You can change also then thickness and style of the border or add other shape and elements inside the layer-list. You can also set again another drawable as background and give shade or transparency as you prefer.

I hope it will help.

like image 169
Daniele D. Avatar answered Dec 10 '22 11:12

Daniele D.


Play Newsstand uses a custom 9-patch with a small drop shadow for its ActionBar background.

But generally the shadow below the ActionBar can be altered by applying Drawable to your theme using the windowContentOverlay attribute.

Here's an example:

<style name="Your.Theme" parent="@android:style/Theme.Holo">
    <item name="android:windowContentOverlay">@drawable/your_drawable</item>
</style>

Here are the 9-patches Play Newsstand uses:

  • MDPI - MDPI

  • HDPI- HDPI

  • XHDPI- XHDPI

Alternatively, you could use the Action Bar Style Generator, which will automagically add it for you to your ActionBar background Drawable.

like image 42
adneal Avatar answered Dec 10 '22 13:12

adneal