一. 设置View透明度
1.在xml文件中设置 ,eg:
android:background="#00000000" 或
android:background="@android:color/transparent"
2.在代码里设置 ,eg:
mAblunImg = (ImageView)findViewById(R.id.ablumimg);
alpha = 100;(0~255)
mAblunImg .setAlpha(alpha);
二 窗口背景设置
1.xml ,在avtivity的theme里使用
android:theme="@android:style/Theme.Translucent"
或在自定义theme中定以,eg:
<stylename="custom_theme"parent="@android:style/Theme.NoTitleBar.Fullscreen" >
<item name="android:windowAnimationStyle">@null</item> <item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowShowWallpaper">true</item>
</style>
2.代码
窗体的透明度 非背景
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha = 1.0f (alpha在0.0f到1.0f之间。1.0完全不透明,0.0f完全透明)
getWindow().setAttributes(lp);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
黑暗度
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.dimAmount=1.0f;(dimAmount在0.0f和1.0f之间,0.0f完全不暗,1.0f全暗)
getWindow().setAttributes(lp);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
设置背景模糊
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
以上设置对dialog对话框同样有效