设置透明度(这是窗体本身的透明度,非背景)

WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha=0.3f;
getWindow().setAttributes(lp);

alpha在0.0f到1.0f之间。1.0完全不透明,0.0f完全透明


设置黑暗度

WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.dimAmount=0.5f;
getWindow().setAttributes(lp);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

dimAmount在0.0f和1.0f之间,0.0f完全不暗,1.0f全暗


设置背景模糊

getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);


设置背景透明度
View v = findViewById(R.id.content);//找到你要设透明背景的layout 的id
v.getBackground().setAlpha(100);//0~255透明度值 ,0为完全透明,255为不透明


以上设置对dialog对话框同样有效

Activity全透明
  
  先在res/values下建colors.xml文件,写入:
  
  <?xmlversion="1.0"encoding="UTF-8"?>
  
  <resources>
  
  <colorname="transparent">#9000</color>
  
  </resources>
  
  这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。
  
  再在res/values/下建styles.xml,设置程序的风格
  
  <?xmlversion="1.0"encoding="utf-8"?>
  
  <resources>
  
  <stylename="Transparent">
  
  <itemname="android:windowBackground">@color/transparent</item>
  
  <itemname="android:windowIsTranslucent">true</item>
  
  <itemname="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
  
  </style>
  
  </resources>
  
  最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任意<activity>标签中添加
  
  android:theme="@style/transparent"
  
  如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。
  
  最后运行程序,发现整个界面都被蒙上一层半透明了。最后可以把背景色#9000换成#0000,运行程序后,就全透明了,看得见背景下的所有东西可以却都操作无效

更多相关文章

  1. [置顶] Android(安卓)Gallery橱窗效果
  2. Android系统Home应用程序(Launcher)的启动过程源代码分析
  3. 使用intent调用Android系统自带应用
  4. Android(安卓)Tips
  5. Android(安卓)progressBar代码设置进度条颜色、背景颜色以及圆角
  6. android camera Intent调用
  7. Qt5.1.1 for android 环境配置
  8. DelphiXE Android的所有权限按照分类总结说明
  9. Android添加背景音乐的方法

随机推荐

  1. 关于android的pan_display
  2. Android(安卓)多种跑马灯的方法
  3. Android(安卓)Material Design Library系
  4. Android实战教程第三篇之简单实现拨打电
  5. Android可以用Html查看器打开txt文件
  6. Android(安卓)判断软件是否第一次打开
  7. Android(安卓)图标外发光
  8. Android(安卓)- 获取版本号、判断当前是
  9. RK3288_Android7.1接eDP屏休眠之后led状
  10. Android(安卓)Fragment onActivityResult