2017-03-02 99 views
-1

我正在创建一个活动并为其动态添加视图。该活动包含一个imageview和一个关闭按钮。我想要实际上是相对布局背景的图像背景是透明的,以便设备的主屏幕上的图标可以被看到。透明背景到Android活动类

我已经试过

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

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

,这也

relativeLayout.setBackgroundColor(0x00000000); 

似乎没有任何工作。任何指针将不胜感激。谢谢。

+0

集这个Android相关联:主题在你的活动'机器人:主题=“@安卓风格/ Theme.Translucent “'n参见 –

+0

试试这个http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android – Akshay

回答

0

帮助设置

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

而且您正在使用的颜色六是错误的...

00000000 is hexa for non transparent white 

使用

Ff000000 instead 

在最顶端的你的ViewGroup有。这将基本上创建一个透明颜色的背景,其他视图将位于该背景上。

您可以使用该地方的其他颜色来调整透明度。

0

您可以创建主题,并将其用于活动

<?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"/> 
0

定义特定活动的主题风格。
在style.xml文件

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

而这种风格在清单与活动

<activity 
     android:name="com.pac.activity.YOURACTIVITY" 
     android:screenOrientation="portrait" 
     android:theme="@style/DialogTheme" > 
</activity>