Android 设置窗体透明度

转自    http://www.xuebuyuan.com/907908.html

1,设置窗体透明度

WindowManager.LayoutParams lp=getWindow().getAttributes();
 lp.alpha=0.5f;
 getWindow().setAttributes(lp);
alpha在0.0f到1.0f之间。

2,设置昏暗度

WindowManager.LayoutParams lp=getWindow().getAttributes();
    lp.dimAmount=0.5f;
  getWindow().setAttributes(lp);
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dimAmount在0.0f和1.0f之间。

3,设置背景模糊
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
      WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

4,调用View方法View view=...
view.getBackground().setAlpha(100);//0~255透明度值 ,0为完全透明,255为不透明

5,在配置文件内activity属性配置内加上
android:theme="@android:style/Theme.Translucent" 
这样就调用了android的透明样式!


你可能感兴趣的:(经验积累,android)