下面是自定义Activity半透明的效果例子:
res/values/styles.xml
<resources>
  <stylename="Transparent ">
    <itemname="android:windowBackground">@color/transparent_background</item>
    <itemname="android:windowNoTitle">true</item>
    <itemname="android:windowIsTranslucent">true</item>  
    <itemname="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
  </style>
</resources>

res/values/color.xml
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
  <colorname="transparent_background">#50000000</color>
</resources>
注意:color.xml的#5000000前两位是透明的效果参数从00 到 ff(透明--不么透明),后6位是颜色的设置manifest.xml
<activityandroid:name=".TransparentActivity"
android:theme="@style/Transparent"/>
java代码
publicvoid onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setTheme(R.style.Transparent); 
        setContentView(R.layout.transparent);
}

下面是利用系统主题实现Activity半透明的效果例子:
Android为透明效果提供了内置的主题:Theme(android:style/Theme.Translucent),如果想实现透明效果,只要为Activity设置该Theme便可。如果想实现半透明效果,则只需要继承android:style/Theme.Translucent,并重写便可。继承android:style/Theme.Translucent并重写:
<?xmlversion=”1.0″ encoding=”utf-8″?>
<resources>
<stylename=”Theme.Translucent” parent=”android:style/Theme.Translucent”>
<itemname=”android:windowBackground”>@color/translucent_background</item>
<itemname=”android:colorForeground”>#fff</item>
</style>
</resources>
AndroidMainfest.xml中使用该主题:
<activityandroid:name=”.Translucent” android:label=”@string/app_name”
android:theme=”@style/Theme.Translucent”>
<intent-filter>
<actionandroid:name=”android.intent.action.MAIN” />
<categoryandroid:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
 
下面是实现View半透明的效果例子:
Button或者ImageButton的背景设为透明或者半透明
半透明:<Button android:background="#e0000000" ... />
透明:    <Button android:background="#00000000" ... />
颜色和不透明度 (alpha) 值以十六进制表示法表示。任何一种颜色的值范围都是 0 到 255(00 到 ff)
。对于 alpha,00 表示完全透明,ff 表示完全不透明。表达式顺序是“aabbggrr”,其中“aa=alpha”
(00 到 ff);“bb=blue”(00 到 ff);“gg=green”(00 到 ff);“rr=red”(00 到 ff)。例如
,如果您希望对某叠加层应用不透明度为 50% 的蓝色,则应指定以下值:7fff0000
设置背景图片透明度(超简单)
Java代码
View v = findViewById(R.id.content);//找到你要设透明背景的layout 的id
v.getBackground().setAlpha(100);//0~255透明度值

Android应用开发中半透明效果实现方案的更多相关文章

  1. Android学习开发中如何保持API的兼容

    Android学习开发中如何保持API的兼容: 1,采用良好的设计思路 在设计过程中,如果能按照下面的方式来进行设计,会让这个API生命更长久 面向用例的设计,收集用户建议,把自己模拟成用户,保证AP ...

  2. Android TV开发中所有的遥控器按键监听及注意事项,新增home键监听

    原文:Android TV开发中所有的遥控器按键监听及注意事项,新增home键监听 简单记录下android 盒子开发遥控器的监听 ,希望能帮到新入门的朋友们 不多说,直接贴代码 public cla ...

  3. Android应用开发中关于this.context=context的理解

    在Android应用开发中,有的类里面需要声明一个Context的成员变量,然后还需要在该类的构造函数中加上this.context=context;这行代码.为什么要这么写呢?不写不行么? 先看下面 ...

  4. Android应用开发中三种常见的图片压缩方法

    Android应用开发中三种常见的图片压缩方法,分别是:质量压缩法.比例压缩法(根据路径获取图片并压缩)和比例压缩法(根据Bitmap图片压缩). 一.质量压缩法 private Bitmap com ...

  5. 【Android】开发中个人遇到和使用过的值得分享的资源合集

    Android-Classical-OpenSource Android开发中 个人遇到和使用过的值得分享的资源合集 Trinea的OpenProject 强烈推荐的Android 开源项目分类汇总, ...

  6. Unity3d Android Http 开发中的坑(吐槽

    在一般的U3D网络开发中,直接使用WWW类便足够正常使用,但我在发现使用WWW下载大文件时,会导致整个程序卡顿的情况(不清楚是否我个人电脑问题),所以干脆使用HttpWebRequest/HttpWe ...

  7. 浅谈Android系统开发中LOG的使用

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6581828 在程序开发过程中,LOG是广泛使用 ...

  8. 浅析Android Camera开发中的三个尺寸和三种变形 (贡献一个自适配Picturesize和Previewsize的工具类)

    转至 (http://blog.csdn.net/yanzi1225627/article/details/17652643) 经常听人问Camera开发中,各种变形问题,今天有空就在此梳理总结下. ...

  9. Web开发中,页面渲染方案

    转载自:http://www.jianshu.com/p/d1d29e97f6b8 (在该文章中看到一段感兴趣的文字,转载过来) 在Web开发中,有两种主流的页面渲染方案: 服务器端渲染,通过页面渲染 ...

随机推荐

  1. 水一道NOIP2002提高组的题【A003】

    [A003]均分纸牌[难度A]———————————————————————————————————————————————————— [题目要求] 有 N 堆纸牌,编号分别为 1,2,…, N.每堆 ...

  2. 2012 Multi-University #10

    容斥原理 A Number Sequence 题意:给出n个数,b1,b2,b3……bn,构造n个数,a1,a2,……an(ai>1),使得a1*a2*a3……an=b1*b2……bn 分析:容 ...

  3. CodeForces 515C. Drazil and Factorial

    C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. codeforces#271 (Div. 2)预处理

    B. Worms time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  5. php查找字符串首次出现的位置 判断字符串是否在另一个字符串中

    strpos - 查找字符串首次出现的位置 说明 int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) 返回 nee ...

  6. ZeroMQ接口函数之 :zmq_errno – 返回errno的值给调用此函数的线程

    ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_errno zmq_errno(3)         ØMQ Manual - ØMQ/3.2.5 Name zm ...

  7. Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  8. ZK textbox Constraint验证

    test.zul: <?page title="" contentType="text/html;charset=UTF-8"?> <zk x ...

  9. innodb Lock wait timeout exceeded;

    当出现:ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction,要解决是一件麻烦的事情:特别是当一个SQL ...

  10. 反射-----学习Spring必学的Java基础知识之一

    Java允许通过程序化的方式间接对Class进行操作,Class文件由类装载器装载后,在JVM中将形成一份描述Class结构的元信息对象,通过该元信息对象可以获知Class的结构信息:如构造函数.属性 ...