原文地址:http://blog.csdn.net/sodino/article/details/5822147

1.Activity全透明

同学zzm给了这个有趣的代码,现在公布出来。

先在res/values下建colors.xml文件,写入:

<? xml   version = "1.0"   encoding = "UTF-8" ?>
< resources >
< color name = "transparent" > #9000 </ color >
</ resources >

这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。

再在res/values/下建styles.xml,设置程序的风格

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Transparent">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
</style>
</resources>

最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任 意<activity>标签中添加

  1. android:theme = "@style/transparent"

如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。

最后运行程序,哈哈,是不是发现整个界面都被蒙上一层半透明了。最后可以把背景色#9000换成#0000,运行程序后,就全透明了,看得见背景下 的所有东西可以却都操作无效。呵呵....

2.Dialog全透明

1.准备保留边框的全透明素材如下图:

2.在values中新建一styles.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="TANCStyle" parent="@android:style/Theme.Dialog">
<!-- 更换背景图片实现全透明 -->
<item name="android:windowBackground">@drawable/panel_background_sodino1</item>
<!-- 屏幕背景不变暗 -->
<item name="android:backgroundDimEnabled">false</item>
<!-- 更改对话框标题栏 -->
<item name="android:windowTitleStyle">@style/TitleStyle</item>
</style>
<style name="TitleStyle" parent="@android:style/DialogWindowTitle">
<item name="android:textAppearance">@style/TitleText</item>
</style>
<style name="TitleText" parent="@android:style/TextAppearance.DialogWindowTitle">
<!-- 设置Dialog标题栏文字颜色。 -->
<item name="android:textColor">#000</item>
</style>
</resources>

3.在layout文件夹下新建一文件句为main_dialog.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000">
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="200px"
android:layout_below="@+id/ImageView01"
android:background="#0000">
<TextView android:id="@+id/TextView01"
android:text="SodinoText"
android:textColor="#f000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000"
></TextView>
</ScrollView>
<Button android:id="@+id/btnCancel"
android:layout_below="@id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Cancel">
</Button>
</RelativeLayout>

4.Activity代码如下:

package lab.sodino.tanc;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TANCAct extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnShow = (Button) findViewById(R.id.btnShow);
btnShow.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
showTANC(
"This is my custom dialog box",
"TextContent/nWhen a dialog is requested for the first time, Android calls onCreateDialog(int) from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.",
"http://blog.csdn.net/sodino");
}
});
}
private void showTANC(String header, String content, String url) {
final Dialog dialog = new Dialog(this, R.style.TANCStyle);
dialog.setContentView(R.layout.main_dialog);
dialog.setTitle(header);
dialog.setCancelable(true);
TextView textView01 = (TextView) dialog.findViewById(R.id.TextView01);
textView01.setText(content + content + content);
Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
dialog.cancel();
}
});
dialog.show();
}
}

最后效果图:

Android有趣的全透明效果--Activity及Dialog的全透明(附android系统自带图标大全)[转]的更多相关文章

  1. 茴香豆的第五种写法---设置ExpandableListView系统自带图标按下效果

    1 编写groupindicator_selector.xml如下: <?xml version="1.0" encoding="utf-8"?> ...

  2. android系统自带图标

      android:src="@android:drawable/ic_media_rew"    

  3. android系统自带图标集合(android.R.drawable查看)

    alert_dark_frame alert_light_frame arrow_down_float arrow_up_float bottom_bar btn_default btn_defaul ...

  4. 【Unity Shader】(五) ------ 透明效果之半透明效果的实现及原理

    笔者使用的是 Unity 2018.2.0f2 + VS2017,建议读者使用与 Unity 2018 相近的版本,避免一些因为版本不一致而出现的问题 [Unity Shader学习笔记](三) -- ...

  5. Unity3D学习(八):《Unity Shader入门精要》——透明效果

    前言 在实时渲染中要实现透明效果,通常会在渲染模型时控制它的透明通道. Unity中通常使用两种方法来实现透明 :(1)透明度测试(AlphaTest)(2)透明度混合(AlphaBlend).前者往 ...

  6. Android基础总结(六)Activity

    创建第二个Activity(掌握) 需要在清单文件中为其配置一个activity标签 标签中如果带有这个子节点,则会在系统中多创建一个快捷图标 <intent-filter> <ac ...

  7. Android 编程下实现 Activity 的透明效果

    实现方式一(使用系统透明样式) 通过配置 Activity 的样式来实现,在 AndroidManifest.xml 找到要实现透明效果的 Activity,在 Activity 的配置中添加如下的代 ...

  8. Android学习之Android 5.0分享动画实现微信点击全屏效果

    Android5.0过渡动画,请看 http://blog.csdn.net/qq_16131393/article/details/51112772 今天用分享动画实现微信点击全屏效果 本文源代码下 ...

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

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

随机推荐

  1. "Could not find the main class: org.apache.catalina.startup.Boostrap. Program will exit."

    尝试将 myeclipse中的编译版本修改(如,将1.5修改为1.6)

  2. C# datatable竖行转换的问题

    这次在做项目中,遇到了这样一个问题:datable中列头的名字是不确定的,从数据库中动态查出来的,假设为typeDATA,行的数据中又包含了列头的信息,并按固定的字段分组,当查处行的数据之后用来填充每 ...

  3. SpringMVC-Spring-Hibernate项目搭建之一-- 搭建maven 项目 & servlet的demo

    一. 搭建maven项目  1. 新建maven项目,选择maven Project --> Next 2. 勾选 Create a simple project --> Next 3. ...

  4. cookies,sessionStorage,localStorage的区别

    sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可以方便的在web请求之间保存数据.有了本地数据,就可以避免数据在浏览器和服务器间不必 ...

  5. cocos2dx切换播放的动画

    版本:cocos2dx 2.2.6 IDE: VS2012 语言:C++98 美术资源一共有两段动画的序列帧,一个是手绘马行走图,一个是分子人行走图. 程序要实现的目的就是在同一个位置,点击按钮可以实 ...

  6. NFS共享权限问题

    //所有web集群节点的用户统一uid 例如888,用户最好也统一 Apache server: useradd -u 888 -s /sbin/nologin -M www chown -R www ...

  7. 为什么stm32有的外设在进行初始化的时候需要将寄存器重设为缺省值?不设置会怎么样?

    首先,缺省值就是默认值的意思,默认值可以理解为设计芯片的人认为用这个参数,比较适中,起码不可能耽误你对某一模块进行驱动.然后,为什么除了默认值(缺省值),还有这么多其他的参数可以进行选择呢,那就要看你 ...

  8. MongoDB出现CPU飚高,如何强制停止正在执行的操作

    如果发出了一个执行耗时很长的任务给MongoDB服务器,客户端强制终止会导致任务依然在服务器端执行. 这时MongoDB提供了查询和管理正在执行任务的方式. // db.currentOp() 获得当 ...

  9. Spring boot + Gradle + Eclipse打war包发布总结

    首先感谢两位博主的分享 http://lib.csdn.net/article/git/55444?knId=767 https://my.oschina.net/alexnine/blog/5406 ...

  10. 使用JavaScript调用aspx后台代码

    方法1:js同步调用 触发: onclick="javascript:share('<%# Eval("id_File") %>')" 页面函数: ...