设置透明效果 大概有三种
1、用android系统的透明效果
Java代码 
android:background="@android:color/transparent" 
例如 设置按钮
Java代码 
<Button android:background="@android:color/transparent"  
 
  android:text="@+id/Button01"  
 
  android:id="@+id/Button01"  
 
  android:layout_width="wrap_content"  
 
  android:layout_height="wrap_content"  
 
  android:textColor="#ffffff" />  
2、用ARGB来控制
Java代码 
半透明<Button android:background="#e0000000" /> 
透明<Button android:background="#00000000" /> 
 
3、设置alpha
Java代码 
View v = findViewById(R.id.content);//找到你要设透明背景的layout 的id 
v.getBackground().setAlpha(100);//0~255透明度值 
 
 
 
 
 
 
android 窗体透明的,黑暗度等的设置技巧
设置透明度(这是窗体本身的透明度,非背景)
1 WindowManager.LayoutParams lp=getWindow().getAttributes();
2 lp.alpha=0.3f;
3 getWindow().setAttributes(lp);
 
alpha在0.0f到1.0f之间。1.0完全不透明,0.0f完全透明

设置黑暗度

1 WindowManager.LayoutParams lp=getWindow().getAttributes();
2 lp.dimAmount=0.5f;
3 getWindow().setAttributes(lp);
4 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
 
dimAmount在0.0f和1.0f之间,0.0f完全不暗,1.0f全暗

设置背景模糊

1 getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
2 WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
 
以上设置对dialog对话框同样有效
 
 
 
Activity的透明、半透明效果的设置transparent
res/values/styles.xml
1
2
3
4
5
6
7
8
9
10
11
12
<resources>  
  <style name="Transparent">  
    <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>
res/values/color.xml
1
2
3
4
5
6
7
<?xml version="1.0" encoding="utf-8"?>  
<resources>  
  <color name="transparent_background">#50000000</color>  
</resources>  
//注意:
//color.xml的#5000000前两位是透明的效果参数从00--99(透明--不怎么透明),
//后6位是颜色的设置
manifest.xml
1
2
3
4
<activity 
android:name=".TransparentActivity" 
android:theme="@style/Transparent">  
</activity>
java代码
1
2
3
4
5
public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setTheme(R.style.Transparent);   
        setContentView(R.layout.transparent);  
}
配置结束。

Android设置透明、半透明等效果的更多相关文章

  1. android设置view透明度的效果

    android设置view透明度的效果 推荐textView.setBackgroundColor(Color.TRANSPARENT);     第一种方法:在xml文件中设置背景颜色. andro ...

  2. android设置背景半透明效果

    1.Button或者ImageButton的背景透明或者半透明 半透明:<Button android:background="#e0000000"···> 透明:&l ...

  3. 第三十九篇、NavBar动态隐藏、设置透明、毛玻璃效果

    1.动态隐藏 - (void)viewDidLoad { [super viewDidLoad]; if ([self respondsToSelector:@selector(automatical ...

  4. Android课程---Android设置透明效果的三种方法(转)

    1.使用Android系统自带的透明效果资源 <Button  android:background="@android:color/transparent"/>   ...

  5. Android设置透明状态

    xml中: android:background="@android:color/transparent" 半透明: android:background="#e0000 ...

  6. android设置透明状态栏

    先是半透明效果(两种方法): 第一种(简单): //直接将下面的代码放在activity中的setContentView(R.layout.activity_main);中之前就行了 if (Buil ...

  7. Android实现透明的颜色效果

    android Button或者ImageButton背景透明状态设置 设置Button或ImageButton的背景为透明或者半透明 半透明< Button android:backgroun ...

  8. Android实现透明的颜色效果(zz)

    android Button或者ImageButton背景透明状态设置 设置Button或ImageButton的背景为透明或者半透明 半透明< Button android:backgroun ...

  9. Android设置透明状态栏和透明导航栏

    Android透明状态栏只有在4.4之后有. 在代码中加入下面几行代码即可实现

随机推荐

  1. C++资料大全

    本文内容源自GitHub<Awesome C/C++>. 关于 C++ 框架.库和资源的一些汇总列表,由 fffaraz 发起和维护. 内容包括:标准库.Web应用框架.人工智能.数据库. ...

  2. Windows下使用批处理设置IP地址,DNS

    自动获取IP地址: echo 本地连接 改成你想要改的连接名 比如 无线网络连接set cname=本地连接 echo %cname% 正在设置自动获得IP地址,请稍等...... netsh int ...

  3. js实现windows扫雷(jquery)

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. linux下进程、端口号相互查看方法

    linux下通过进程名查看其占用端口: 1.先查看进程pid ps -ef | grep 进程名 2.通过pid查看占用端口 netstat -nap | grep 进程pid 例:通过nginx进程 ...

  5. activiti自定义流程之自定义表单(一):环境配置

    先补充说一下自定义流程整个的思路,自定义流程的目的就是为了让一套代码解决多种业务流程,比如请假单.报销单.采购单.协作单等等,用户自己来设计流程图. 这里要涉及到这样几个基本问题,一是不同的业务需求, ...

  6. PHP解码unicode编码中文字符代码示例

    在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...

  7. .net EntityFramework用法探索系列 1

    EntityFramework用法探索系列 (一)DatabaseFirst (二)CodeFirst (三)CodeFirst流畅API (四)Repository和UnitOfWork (五)引入 ...

  8. IO - IOUtils

    Commons IO is a library of utilities to assist with developing IO functionality. There are four main ...

  9. CF 161D Distance in Tree 树形DP

    一棵树,边长都是1,问这棵树有多少点对的距离刚好为k 令tree(i)表示以i为根的子树 dp[i][j][1]:在tree(i)中,经过节点i,长度为j,其中一个端点为i的路径的个数dp[i][j] ...

  10. gridView--GridView关于间距的属性值介绍

    android:columnWidth  设置列的宽度.关联的方法为:setColumnWidth(int) android:gravity  设置此组件中的内容在组件中的位置.可选的值有:top.b ...