문제

How can I draw an action bar 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 colour

thanks!

도움이 되었습니까?

해결책

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.

다른 팁

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:

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top