2

I am creating an activity and adding views to it dynamically. This activity contains an imageview and a close button. I want the background of the image which is in fact the relative layout background to be transparent so that the icons on the home screen of the device could be visible.

I have tried

    Window window = this.getWindow();
 window.setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));

and also

relativeLayout.setBackgroundColor(Color.parseColor("#00000000")); 

and this as well

relativeLayout.setBackgroundColor(0x00000000);

Nothing seems to work. Any pointers will be appreciated. Thanks.

D'yer Mak'er
  • 1,632
  • 5
  • 24
  • 47
  • set this android:theme in your activity `android:theme="@android:style/Theme.Translucent"` n see – Charuක Mar 02 '17 at 12:19
  • try this http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android – Akshay Mar 02 '17 at 12:24

4 Answers4

5

you can create theme and use it for activity

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>

<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent"/>
santosh kumar
  • 2,952
  • 1
  • 15
  • 27
2

Define style theme for particular Activity.
In style.xml file

<style name="DialogTheme" parent="android:Theme.Holo.Light.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
</style>

And associate this style in Manifest with activity

<activity
        android:name="com.pac.activity.YOURACTIVITY"
        android:screenOrientation="portrait"
        android:theme="@style/DialogTheme" >
</activity>
Garg
  • 2,731
  • 2
  • 36
  • 47
0

Hi use this link http://angrytools.com/android/button/. its help for you

0

Set the

android:background="@android:color/transparent"

Also the colour hexa you are using is wrong...

00000000 is hexa for non transparent white

Use

Ff000000 instead

In the top most viewgroup you have. This will essentially create a background with transparent colour on which other views will lie.

You can adjust transparency using other colours in that place.

Kushan
  • 5,855
  • 3
  • 31
  • 45