Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why is background overlapping drawable resource in android

I was following a tutorial when I stumbled on something I couldn’t quite wrap my head around. This is the drawable resource that I use as the source for an image button.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape
            android:shape="rectangle">
            <stroke android:width="2dp"
                android:color="@color/light_silver"/>

            <padding android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp"/>
        </shape>
    </item>

    <item>
        <shape android:shape="rectangle">
            <stroke android:width="2dp"
                android:color="@color/light_silver"/>
            <solid android:color="#00000000"/>
            <corners android:radius="10dp"/>
        </shape>
    </item>
</layer-list>

And this is the ImageButton.

<ImageButton
            android:layout_height="25dp"
            android:layout_width="25dp"
            android:layout_margin="2dp"
            android:src="@drawable/pallet_normal"
            android:background="@color/yellow"
            android:tag="@color/yellow"/>

and this is the result that is created from this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I don’t understand why the background is overlapping the drawable resource. Isn’t the middle of the drawable supposed to be black as that’s what I set in the solid tag? Please help, I am very confused.

>Solution :

You use a transparent color by setting the alpha channel to 00 which made the color full transparent; to make it full opaque, you can set it to ff >> <solid android:color="#ff000000"/> or remove the alpha channel by only using 6-digit color >> <solid android:color="#000000"/>.

For extra help about using the alpha digits in android, pls check out this question.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading