Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rectangle shape as background causes black background

I would like to create a border around my RableRow. I am using the following shape as background.

bg_stroke_dotted_right

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list  xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:top="-4dp"
            android:left="-2dp"
            android:bottom="-4dp" 

            android:drawable="@drawable/stroke_dotted">
        </item>
    </layer-list>

stroked_dotted drawable

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <solid android:color="#000000" />
        <stroke
            android:dashGap="4dp"
            android:dashWidth="2dp"
            android:width="2dp"
            android:color="@color/greyDark" />

    </shape>

I do not understand why using "bg_stroke_dotted_right" as bg - files the background with black color. As soon as I add "bg_stroke_dotted_right" as bg - the bg turns to black.

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_stroke_dotted_right"
            >

enter image description here

like image 505
Skip Avatar asked Apr 06 '14 22:04

Skip


2 Answers

in the shape try this :

<solid android:color="#00000000" />

in this case the first 2 "00" are the alpha of the colors, and "00" meand transparent.

enjoy!

like image 105
user3574454 Avatar answered Nov 14 '22 14:11

user3574454


The accepted answer suggests to use transparent in the solid element. Where as this is the reason for the bug (missing the solid element falls back to black on android <4.2) the solution is not the most optimal.

For starters instead of hard code the colour you can use @android:color/transparent however it's potentially best to use @null so that it doesn't overdraw. Something like this:

<solid android:color="@null" />
like image 8
pablisco Avatar answered Nov 14 '22 14:11

pablisco