|
1. 在res/values 下建立color.xml
<resources> <color
name="transparent_background">#80ffffff</color>
</resources>PS:
#80是透明度的值(即80%透明),ffffff是颜色值(为黑色)
2. 在res/values下建立style.xml
<resources> <style name="Transparent"
parent="android:style/Theme.Dialog"> <item
name="android:windowBackground">@color/transparent_background</item>
<item name="android:windowNoTitle">true</item> <item
name="android:windowIsTranslucent">true</item> <item
name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
</style></resources>PS: parent="android:style/Theme.Dialog"
是将activity设置为弹出式窗口
3. 在AndroidManifest.xml中找到要弹出的activity,加入theme:
<activity
android:name="ActivityName" android:theme="@style/Transparent"
/>完成上面设置后,你的activity就已经是透明的了,但是该Activity中的控件还没有透明,如果还需要控件透明,则需要在该activity的代码中加入如下代码:
//设置activity中的控件透明 Window window = getWindow(); WindowManager.LayoutParams
wl = window.getAttributes(); wl.flags =
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
wl.alpha=0.95f;//设置透明度,0.0为完全透明,1.0为完全不透明 window.setAttributes(wl);
| |