Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set shape background to transparent in android

I have a shape drawable that I want to use as a background. I want the shape to be transparent. But so far it's not. How do I do that? Here is what I have:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >

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

    <stroke
        android:width="1dip"
        android:color="#000000" />

    <corners android:radius="10dp" />

</shape>

I expected the line <solid android:color="#80000000" /> to do the trick.

EDIT:

In manifest, I set android:theme="@android:style/Theme.Dialog". Could that be the cause of the problem? I am basically trying to get this view on top of another. Changing to 00 or FF or whatever else does not work.

like image 902
Cote Mounyo Avatar asked Jul 03 '13 22:07

Cote Mounyo


2 Answers

if you want set shape background to transparent you need to set this color

<solid android:color="#00000000" />
like image 113
Volodymyr Yatsykiv Avatar answered Oct 06 '22 00:10

Volodymyr Yatsykiv


for creating a color including an opacity effect, you can create a color with taking the alpha channel into account.

<resources>
<color name="translucent_grey">#88cccccc</color>
</resources>

a quote from another User about the color formats:

When defining the color of a view in android, the format can be either #RRGGBB or #AARRGGBB, where AA is the hex alpha value. FF would be fully opaque and 00 would be full transparent.

more information about this technique can be found in this thread: How to Set Opacity (Alpha) for View in Android

Regards, Jim

like image 40
Jimpi Avatar answered Oct 05 '22 22:10

Jimpi