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"
>
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!
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With