Transparency in a background of a View in android can be achieved in two ways.
1. By providing a transparent image.
2. By providing an XML that has as shape with end, starting and middle color.

This is a sample XML that creates a transparency.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
                android:endColor ="#FFFFFF"
                android:angle="270" />
                android:color="#C2C2C2" />
                android:radius="3dp" />
            <padding android:left="5dp"

Note : By Simply providing a color doesn’t creates transparency.
The trick lies in the 8-digit code for the color.
The thing is that the last 6 letters represent the original color. The first 2 letter determines it’s alpha or Transparency.

The advantages of this type of xml is that.
1. We can have gradient of colors.
2. we can have gradient in any direction.
3. We have have strokes around the image.
4. we can reduce the size of our application without using an image for this transparency.
5. we can provide padding to them.
6. Most importantly we can have rounded corners to which ever view we apply this as background.

This is how it is applied in XML.


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.