如何利用Activity的Dialog风格完成mui弹出框框设计

4745人阅读
【Android 基础】(20)
在Android中经常会遇到需要使用Dialog风格弹出框的activity,首先我们可能会首先想到的是在XML布局文件中设置android:layout_height=&wrap_content&属性,让activity的高度自适应,显然这还不行,我们还需要为其DialogActivity设置自定义一个样式
&style name=&dialogstyle&&
&!--设置dialog的背景--&
&item name=&android:windowBackground&&@android:color/transparent&/item&
&!--设置Dialog的windowFrame框为无--&
&item name=&android:windowFrame&&@null&/item&
&!--设置无标题--&
&item name=&android:windowNoTitle&&true&/item&
&!--是否浮现在activity之上--&
&item name=&android:windowIsFloating&&true&/item&
&!--是否半透明--&
&item name=&android:windowIsTranslucent&&true&/item&
&!--设置窗口内容不覆盖--&
&item name=&android:windowContentOverlay&&@null&/item&
&!--设置动画,在这里使用让它继承系统的Animation.Dialog--&
&item name=&android:windowAnimationStyle&&@android:style/Animation.Dialog&/item&
&!--背景是否模糊显示--&
&item name=&android:backgroundDimEnabled&&true&/item&
&/style&然后在AndroidManifest.xml中设置DialogActivity的样式为我们自定义的dialogstyle
如下是布局的代码
&?xml version=&1.0& encoding=&utf-8&?&
&LinearLayout xmlns:android=&/apk/res/android&
android:layout_width=&match_parent&
android:layout_height=&wrap_content&
android:background=&@color/white&
android:orientation=&vertical&&
&LinearLayout
android:layout_width=&match_parent&
android:layout_height=&65dp&
android:orientation=&horizontal&
android:paddingLeft=&@dimen/acitvity_margin&
android:paddingRight=&@dimen/acitvity_margin&&
&LinearLayout
android:layout_width=&0dp&
android:layout_height=&match_parent&
android:layout_weight=&1&
android:orientation=&horizontal&&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:gravity=&center&
android:text=&上班时间:&
android:textColor=&@color/grey&
android:textSize=&@dimen/size_text_medium& /&
android:id=&@+id/tv_signin_time&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:background=&@color/white&
android:gravity=&center&
android:text=&9:00&
android:textColor=&@color/grey&
android:textSize=&@dimen/size_text_medium& /&
&/LinearLayout&
&LinearLayout
android:layout_width=&0dp&
android:layout_height=&match_parent&
android:layout_weight=&1&
android:orientation=&horizontal&&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:gravity=&center&
android:text=&下班时间:&
android:textColor=&@color/grey&
android:textSize=&@dimen/size_text_medium& /&
android:id=&@+id/tv_signout_time&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:background=&@color/white&
android:gravity=&center&
android:text=&18:00&
android:textColor=&@color/grey&
android:textSize=&@dimen/size_text_medium& /&
&/LinearLayout&
&/LinearLayout&
&RelativeLayout
android:layout_width=&match_parent&
android:layout_height=&65dp&
android:paddingLeft=&@dimen/acitvity_margin&
android:paddingRight=&@dimen/acitvity_margin&&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_alignParentLeft=&true&
android:gravity=&center&
android:text=&公司位置:&
android:textColor=&@color/grey&
android:textSize=&@dimen/size_text_medium& /&
android:id=&@+id/et_address&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_marginLeft=&2dp&
android:layout_toRightOf=&@+id/tv_address&
android:background=&@color/white&
android:hint=&请输入公司位置&
android:singleLine=&true&
android:textSize=&@dimen/size_text_small& /&
android:id=&@+id/tv_location&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:layout_alignParentRight=&true&
android:layout_centerInParent=&true&
android:gravity=&center&
android:padding=&5dp&
android:text=&重新定位&
android:textColor=&@color/blue&
android:textSize=&@dimen/size_text_medium& /&
&/RelativeLayout&
&RelativeLayout
android:layout_width=&match_parent&
android:layout_height=&65dp&
android:paddingLeft=&@dimen/acitvity_margin&
android:paddingRight=&@dimen/acitvity_margin&&
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_alignParentLeft=&true&
android:gravity=&center&
android:text=&设置管理员:&
android:textColor=&@color/grey&
android:textSize=&@dimen/size_text_medium& /&
&ImageView
android:layout_width=&wrap_content&
android:layout_height=&match_parent&
android:layout_alignParentRight=&true&
android:gravity=&center&
android:src=&@mipmap/icon_toright& /&
&/RelativeLayout&
&/LinearLayout&
接下来我们再看一下效果图是不是我们想要的呢
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:172013次
积分:2384
积分:2384
排名:第16724名
原创:53篇
评论:134条
文章:38篇
阅读:110105
(4)(1)(1)(1)(5)(7)(1)(5)(1)(7)(4)(4)(8)(7)(2)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'Android中使用Dialog风格弹出框的Activity - 简书
Android中使用Dialog风格弹出框的Activity
在Android中经常会遇到需要使用Dialog风格弹出框的activity,首先我们可能会首先想到的是在XML布局文件中设置android:layout_height="wrap_content"属性,让activity的高度自适应,显然这还不行,我们还需要为其DialogActivity设置自定义一个样式
&style name="dialogstyle"&
&!--设置dialog的背景--&
&item name="android:windowBackground"&@android:color/transparent&/item&
&!--设置Dialog的windowFrame框为无--&
&item name="android:windowFrame"&@null&/item&
&!--设置无标题--&
&item name="android:windowNoTitle"&true&/item&
&!--是否浮现在activity之上--&
&item name="android:windowIsFloating"&true&/item&
&!--是否半透明--&
&item name="android:windowIsTranslucent"&true&/item&
&!--设置窗口内容不覆盖--&
&item name="android:windowContentOverlay"&@null&/item&
&!--设置动画,在这里使用让它继承系统的Animation.Dialog--&
&item name="android:windowAnimationStyle"&@android:style/Animation.Dialog&/item&
&!--背景是否模糊显示--&
&item name="android:backgroundDimEnabled"&true&/item&
然后在AndroidManifest.xml中设置DialogActivity的样式为我们自定义的dialogstyle
如下是布局的代码
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"&
&LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal"
android:paddingLeft="@dimen/acitvity_margin"
android:paddingRight="@dimen/acitvity_margin"&
&LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="上班时间:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
android:id="@+id/tv_signin_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="9:00"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
&/LinearLayout&
&LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="下班时间:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
android:id="@+id/tv_signout_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="18:00"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
&/LinearLayout&
&/LinearLayout&
&RelativeLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:paddingLeft="@dimen/acitvity_margin"
android:paddingRight="@dimen/acitvity_margin"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="公司位置:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
android:id="@+id/et_address"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_toRightOf="@+id/tv_address"
android:background="@color/white"
android:hint="请输入公司位置"
android:singleLine="true"
android:textSize="@dimen/size_text_small" /&
android:id="@+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="5dp"
android:text="重新定位"
android:textColor="@color/blue"
android:textSize="@dimen/size_text_medium" /&
&/RelativeLayout&
&RelativeLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:paddingLeft="@dimen/acitvity_margin"
android:paddingRight="@dimen/acitvity_margin"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="设置管理员:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
&ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="center"
android:src="@mipmap/icon_toright" /&
&/RelativeLayout&
&/LinearLayout&
接下来我们再看一下效果图是不是我们想要的呢
你的努力程度之低,根本轮不到拼天赋
Android开发者
http://blog.csdn.net/qq_博客分类:
达到的效果就像google自带的搜索widiget中,点击录音键弹出的对话框效果一样
除了一个dialog,没有其他的东西,而且背景是半透明的。
在网上搜了一下,android自带theme如下:
oandroid:theme="@android:style/Theme.Dialog"
将一个Activity显示为对话框模式
oandroid:theme="@android:style/Theme.NoTitleBar"
不显示应用程序标题栏
oandroid:theme="@android:style/Theme.NoTitleBar.Fullscreen"
不显示应用程序标题栏,并全屏
oandroid:theme="Theme.Light"
背景为白色
oandroid:theme="Theme.Light.NoTitleBar"
白色背景并无标题栏
oandroid:theme="Theme.Light.NoTitleBar.Fullscreen"
白色背景,无标题栏,全屏
oandroid:theme="Theme.Black"
oandroid:theme="Theme.Black.NoTitleBar"
黑色背景并无标题栏
oandroid:theme="Theme.Black.NoTitleBar.Fullscreen"
黑色背景,无标题栏,全屏
oandroid:theme="Theme.Wallpaper"
用系统桌面为应用程序背景
oandroid:theme="Theme.Wallpaper.NoTitleBar"
用系统桌面为应用程序背景,且无标题栏
oandroid:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"
用系统桌面为应用程序背景,无标题栏,全屏
oandroid:theme="Translucent"
oandroid:theme="Theme.Translucent.NoTitleBar"
oandroid:theme="Theme.Translucent.NoTitleBar.Fullscreen"
oandroid:theme="Theme.Panel"
oandroid:theme="Theme.Light.Panel"
其实,只要在manifest.xml文件中把&application&中设置为android:theme = "@android:style/Theme.Dialog"即可,效果如下:
handspeaker
浏览: 37873 次
来自: 北京
sarkey123 写道 正在学习这方面的东西啊这个是很久以前 ...
正在学习这方面的东西啊
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'当前位置: >
一个炫酷弹出指示层可以自定义的UI,内置多种主题的Android提示
时间: 09:25 来源:互联网 作者:源码搜藏 浏览:
源码类别:对话框Dialog
源码大小:未知
编码格式:gbk
授权方式:免费源码
运行环境:Android studio
官方网址:暂无
欢迎加入QQ群讨论学习
LemonHello4Android
妈妈说,问人问题要先说你好,那么咱这个全平台的理论上做的最牛逼的对话框(只是理论上)就叫LemonHello吧~ 完全可以自定义的UI,内置多种主题提示框。
作者:1em0nsOft - LiuRi
版本号:1.0.1
简介:这是一个完全Made in China的炫酷弹出指示层Android版本(-_-#意思就是还有iOS的),他能让你快速的自定义任何样式的弹出框。
意见建议反馈QQ群: (还寻思啥呢,赶紧加啊!)
怎么样,别光看,我们不妨试试看哦!把LemonHello集成到你的项目中很简单,使用Gradle,首先在你的Project build.gradle文件中(allprojects -&repositories节点)加入如下代码:
allprojects {
repositories {
// 加入下面这行
maven { url 'https://jitpack.io' }
接下来,在你的项目中的Module(xxx e.g:app) build.gradle中(dependencies节点)加入如下代码:
dependencies {
你的其他依赖
// 然后加入下面这行
compile 'com.github.1em0nsOft:LemonHello4Android:1.0.1'
最后重新build一下就可以啦。
接下来,我们验证一下我们是否集成成功,随便找一个Activity,在onCreate方法里面我们加上如下一段代码来弹出一个对话框试试:
LemonHello.getSuccessHello(&提示&, &恭喜您,集成成功!&)
.addAction(new LemonHelloAction(&我知道啦&, new LemonHelloActionDelegate() {
public void onClick(LemonHelloView helloView, LemonHelloInfo helloInfo, LemonHelloAction helloAction) {
helloView.hide();
.show(MainActivity.this);
运行一下,你就可以看到你使用LemonHello弹出的第一个对话框咯~集成成功!
LemonBubble默认带了四中样式,就如我们开头展示的动画里面的前四种,不过呢,你可以自定义其他样式,都可以自定义什么属性呢?给大家列一个列表:
// 对话框控件的宽度
// 对话框控件的圆角半径
// 对话框面板的背景颜色
panelBackgroundC
// 对话框面板的背景Drawable
panelBackgroundD
// 对话框的背景蒙版颜色
// 对话框的图标绘制上下文
// 如果icon属性为空,那么会调用该属性iconPaintContext绘制
// 如果iconPaintContext为空,那么会认为无图标
iconPaintC
// 图标动画是否需要重复
isIconAnimationR
// 动画的执行的所需时长
animationT
// 对话框的图标对象
// 如果该对象为空,那么会调用iconPaintContext绘制
// 如果iconPaintContext为空,那么会认为无图标
// 图标的宽度
// 图标为正方形,因此宽度也就是高度
// 图标的位置描述属性
// 对话框的标题,如果该属性为null或空字符串,那么认为其没有标题
// 对话框的正文内容文字
// 标题文字的颜色
// 对话框正文内容文字颜色
// 标题文字的字体大小
titleFontS
// 对话对征文内容文字字体大小
contentFontS
// 标题的按钮文字大小
buttonFontS
// 控件的内边距
// 控件的间隙
// action按钮的高度
actionLineH
// 对话框的动画list(按钮说明信息list)
// 第一行的按钮数量
// 如果超过这个数量,那么每一个Action都会被放到单独的行中
// 如果该数值设置为&1的数字,那么认为该值为1
firstLineButtonC
// 是否显示状态栏
isShowStatusB
// 状态栏的颜色
statusBarC
// LemonHello的事件代理
// 是否使用消息队列,若您使用了消息队列,那么后通知显示的消息框会在前一个消息框关闭后再显示
useMessageQueue
怎么样,够你用吗?我屮HU,还不够吗?那你赶紧告诉我,还需要什么场景,我给你加上!!!!
LemonBubble是一款纯国产、开源、且有售后的提示框控件!有bug,我来改!有需求,我来加!你负责用就行~ 对了,你还有个职责,别忘了点一个star~
我的废话说完了,你也是不是该来体验一下啦!
转载请注明出处
源码搜藏网所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与源码搜藏网无关Android使用Dialog风格弹出框的Activity
字体:[ ] 类型:转载 时间:
这篇文章主要为大家详细介绍了Android使用Dialog风格弹出框的Activity,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
在Android中经常会遇到需要使用Dialog风格弹出框的activity,首先我们可能会首先想到的是在XML布局文件中设置android:layout_height="wrap_content"属性,让activity的高度自适应,显然这还不行,我们还需要为其DialogActivity设置自定义一个样式&
&style name="dialogstyle"&
&!--设置dialog的背景--&
&item name="android:windowBackground"&@android:color/transparent&/item&
&!--设置Dialog的windowFrame框为无--&
&item name="android:windowFrame"&@null&/item&
&!--设置无标题--&
&item name="android:windowNoTitle"&true&/item&
&!--是否浮现在activity之上--&
&item name="android:windowIsFloating"&true&/item&
&!--是否半透明--&
&item name="android:windowIsTranslucent"&true&/item&
&!--设置窗口内容不覆盖--&
&item name="android:windowContentOverlay"&@null&/item&
&!--设置动画,在这里使用让它继承系统的Animation.Dialog--&
&item name="android:windowAnimationStyle"&@android:style/Animation.Dialog&/item&
&!--背景是否模糊显示--&
&item name="android:backgroundDimEnabled"&true&/item&
然后在AndroidManifest.xml中设置DialogActivity的样式为我们自定义的dialogstyle
如下是布局的代码&
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"&
&LinearLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal"
android:paddingLeft="@dimen/acitvity_margin"
android:paddingRight="@dimen/acitvity_margin"&
&LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="上班时间:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
android:id="@+id/tv_signin_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="9:00"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
&/LinearLayout&
&LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="下班时间:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
android:id="@+id/tv_signout_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:text="18:00"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
&/LinearLayout&
&/LinearLayout&
&RelativeLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:paddingLeft="@dimen/acitvity_margin"
android:paddingRight="@dimen/acitvity_margin"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="公司位置:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
android:id="@+id/et_address"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_toRightOf="@+id/tv_address"
android:background="@color/white"
android:hint="请输入公司位置"
android:singleLine="true"
android:textSize="@dimen/size_text_small" /&
android:id="@+id/tv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="5dp"
android:text="重新定位"
android:textColor="@color/blue"
android:textSize="@dimen/size_text_medium" /&
&/RelativeLayout&
&RelativeLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:paddingLeft="@dimen/acitvity_margin"
android:paddingRight="@dimen/acitvity_margin"&
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="设置管理员:"
android:textColor="@color/grey"
android:textSize="@dimen/size_text_medium" /&
&ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="center"
android:src="@mipmap/icon_toright" /&
&/RelativeLayout&
&/LinearLayout&
接下来我们再看一下效果图是不是我们想要的呢
源码下载:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具}

我要回帖

更多关于 弹出框 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信