Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shape drawable as background, a line at the bottom

I am using a drawable as a background of a TextView just to have a divider line below the text. A achivied it with this drawable-xml:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >     <item>         <shape          android:shape="rectangle">             <solid android:color="#FFDDDDDD" />             <gradient                  android:angle="0"                 android:startColor="#FFAAAAAA"                 android:endColor="#FFEEEEEE"                 />         </shape>     </item>      <item android:bottom="2dp">         <shape          android:shape="rectangle">             <solid android:color="#FF000000" />         </shape>     </item>  </layer-list> 

But this method draws a colored rectangle above a black rectangle. I would like to have just the line at the bottom of the shape with no black rectangle because black is not transparent. How could I achieve that?

like image 218
ZoolWay Avatar asked Mar 28 '12 21:03

ZoolWay


People also ask

Is a drawable to use as the background?

NinePatch drawables. A NinePatchDrawable graphic is a stretchable bitmap image that you can use as the background of a view. Android automatically resizes the graphic to accommodate the contents of the view.

How do you put a background color in a shape?

Click Shape Fill, and under Theme Colors, pick the color you want. Select the shape or text box. On the Drawing Tools Format tab, click Shape Fill > More Fill Colors.

What is stroke in drawable android?

Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.


1 Answers

This is how I got a line at the bottom for mine. Draw a stroke but then shift the item up and to the sides to get the top and sides to not show the stroke:

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">     <item android:top="-8dp" android:left="-8dp" android:right="-8dp">         <shape>              <solid android:color="#2b7996"/>             <stroke android:color="#33b5e5" android:width="6dp"/>         </shape>     </item> </layer-list> 
like image 170
Go Rose-Hulman Avatar answered Sep 19 '22 08:09

Go Rose-Hulman