Android UI设计--半透明效果对话框及activity(可做遮罩层)
下面是style的一些属性及其解释
<style name="dialog_translucent" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item><!-- 边框 --> <item name="android:windowIsFloating">true</item><!-- 是否悬浮在activity上 --> <item name="android:windowIsTranslucent">false</item><!-- 半透明 --> <item name="android:windowNoTitle">true</item><!-- 无标题 --> <item name="android:windowBackground">@android:color/transparent</item><!-- 背景透明 --> <item name="android:backgroundDimEnabled">false</item><!-- 模糊 --> <item name="android:backgroundDimAmount">0.6</item><!-- 灰度 --> <item name="android:windowContentOverlay">@null</item><!-- 对话框是否有遮盖 --> <item name="android:windowAnimationStyle">@style/dialog_animation</item><!-- 弹出或者进入时的动画效果 --> <item name="android:colorBackgroundCacheHint">@null</item><!-- 背景缓存颜色 --> </style>
自定义对话框效果如下

styles.xml
<style name="popupDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@drawable/filled_box</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowIsTranslucent">false</item> <item name="android:backgroundDimAmount">0.6</item> <item name="android:windowAnimationStyle">@style/dialog_animation</item> </style>
filled_box.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#9000"/> <stroke android:width="3dp" color="#ffff8080"/> <corners android:radius="30dp"/> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp"/></shape>
dialog_animation.xml
<style name="dialog_animation"> <item name="android:windowEnterAnimation">@anim/fading_in</item> <item name="android:windowExitAnimation">@anim/fading_out</item> </style>
在anim目录下创建fading_in.xml,进入时候的淡入效果
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" /></set>
fading_out.xml淡出效果
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:duration="500" android:fromAlpha="1.0" android:toAlpha="0.1" /></set>
showVerify方法,效果如上面图所示
private void verifyDialog(String msg) { final Dialog dialog = new Dialog(MainActivity.this, R.style.popupDialog); dialog.setContentView(R.layout.verify_dialog); dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false); TextView message = (TextView)dialog.getWindow().findViewById(R.id.messageTxt); Button okBtn = (Button)dialog.getWindow().findViewById(R.id.dismissBtn); message.setText(msg); okBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(dialog!=null && dialog.isShowing()) { dialog.dismiss(); } } }); if(dialog!=null && !dialog.isShowing()) { dialog.show(); } }
如果是想把整个activity做成类似于微博的new feature透明背景样式,如图

上面的图是透明背景,透明颜色可以自己定义
styles.xml
<style name="activity_translucent"> <item name="android:windowBackground">@drawable/filled_activity_bg</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">false</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@style/dialog_animation</item> <item name="android:colorBackgroundCacheHint">@null</item> <item name="android:backgroundDimAmount">0.6</item><!-- 灰度 --> </style>
如果想设置的不是纯透明,改成灰色透明度的,可以设置windowBackground背景,下面是filled_activity_bg.xml,这样就是灰色的透明背景,类似于第一张图片
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#9000"/> <stroke color="#ffff8080"/></shape>
如果不做任何灰度处理,效果如上图,可以设置背景色为透明
<style name="activity_translucent"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">false</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@style/dialog_animation</item> <item name="android:colorBackgroundCacheHint">@null</item> </style>
显示activity,代码如下。可以通过类似的原理制作遮罩层,其他的半透明能效果,例如popup菜单半透明效果等
Dialog dialog = new Dialog(MainActivity.this, R.style.activity_translucent); dialog.setContentView(R.layout.transparent_layout); dialog.show();
Android UI设计--半透明效果对话框及activity(可做遮罩层)的更多相关文章
- Android UI设计
Android UI设计--PopupWindow显示位置设置 摘要: 当点击某个按钮并弹出PopupWindow时,PopupWindow左下角默认与按钮对齐,但是如果PopupWindow是下图的 ...
- 详解 “Android UI”设计官方教程
我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...
- 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面
[Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...
- 【转】【Android UI设计与开发】之详解ActionBar的使用,androidactionbar
原文网址:http://www.bkjia.com/Androidjc/895966.html [Android UI设计与开发]之详解ActionBar的使用,androidactionbar 详解 ...
- shape和selector是Android UI设计中经常用到的
shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...
- (转载)Android UI设计之AlertDialog弹窗控件
Android UI设计之AlertDialog弹窗控件 作者:qq_27630169 字体:[增加 减小] 类型:转载 时间:2016-08-18我要评论 这篇文章主要为大家详细介绍了Android ...
- 移动周报:十款最实用的Android UI设计工具
上一周可以说是一个不断Mark周,从最实用的Android UI设计工具.免费移动应用测试框架推荐,到HTML5开发框架等等,各种开发工具.框架精彩丰呈,看得小伙伴们是不亦乐乎.当然,还有不容错过的M ...
- Android UI设计的基本元素有哪些
在android app开发如火如荼的今天,如何让自己的App受人欢迎.如何增加app的下载量和使用量....成为很多android应用开发前,必须讨论的问题.而ui设计则是提升客户视觉体验度.提升下 ...
- 巧用Drawable 实现Android UI 元素间距效果
源文地址: 巧用Drawable 实现Android UI 元素间距效果 在大部分的移动UI或者Web UI都是基于网格概念而设计的.这种网格一般都是有一些对其的方块组成,然后它们组合成为一个块.使用 ...
随机推荐
- ArcMap所有Command GUID
The information in this topic is useful if you're trying to programmatically find a built-in command ...
- helm istio k8s docker
helm https://hub.helm.sh/ k8s https://www.kubernetes.org.cn/k8s istio 微服务 https://istio.io/
- 阿里短信接口使用(JAVA版)
近期项目需要使用短信接口,对比下选择了阿里的短信接口 以下为开发笔记: maven pom.xml中引入: <dependency> <groupId>com.aliyun&l ...
- Bootstrap历练实例:成功按钮
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 科普NDIS封包过滤
闲言: 这个月一直在学习NDIS驱动编程,杂七杂八的资料都看个遍了,做了点笔记,捋捋思路,发上来备忘. Ps:只是小菜的一点学习笔记,没什么技术含量,不过版主如果觉得对大家稍微有点帮助的话 ...
- HDU-1312-Black and Red
这题其实和POJ的1979是同一道题,当时POJ使用cin写的,所以读入的时候,就很正确. 这次用scanf读入的时候,就出现了问题,我们在读完宽高之后,要用getchar吸收掉回车,然后每行末尾的回 ...
- python面向对象编程(OOP)
python作为一种解释性语言,其主要的编程方式就是面向对象,而且python的框架django也是主要面向对象的编程. 类(class)和对象(object) 类(class)是用来描述具有相同属性 ...
- 【Gradle】Downloading https://services.gradle.org/distributions/gradle-3.3-bin.zip 失败
提示连接超时 Downloading https://services.gradle.org/distributions/gradle-3.3-bin.zip 失败 这时候需要单独去官网下载包,然后放 ...
- verilog behavioral modeling --procedural assignments
1.procedural assignments are used for updating reg ,integer , time ,real,realtime and memory data ty ...
- Day12装饰器
1.装饰器 什么是装饰器:装饰器指的是为被装饰对象添加新功能的工具 装饰器本身可以是任意调用对象 被装饰对象本身也可以是任意可调用对象 2.为何要用装饰器: 开放封闭原则: ①对修改源代码和调用方式是 ...