设置theme实现类似于自定义dialog效果
2016-06-14 16:49
423 查看
我们知道我们要实现自定义dialog可以自己自定义,那么还有一种方法就是让activity变成窗体,那么我们在设置Theme就可以了
我们来看效果
点击后弹出一个类似气泡的东西
Android平台定义的主题样式:
android:theme=”@android:style/Theme.Dialog” 将一个Activity显示为对话框模式
•android:theme=”@android:style/Theme.NoTitleBar” 不显示应用程序标题栏
•android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” 不显示应用程序标题栏,并全屏
•android:theme=”@android:style/Theme.Light” 背景为白色
•android:theme=”@android:style/Theme.Light.NoTitleBar” 白色背景并无标题栏
•android:theme=”@android:style/Theme.Light.NoTitleBar.Fullscreen” 白色背景,无标题栏,全屏
•android:theme=”@android:style/Theme.Black” 背景黑色
•android:theme=”@android:style/Theme.Black.NoTitleBar” 黑色背景并无标题栏
•android:theme=”@android:style/Theme.Black.NoTitleBar.Fullscreen” 黑色背景,无标题栏,全屏
•android:theme=”@android:style/Theme.Wallpaper” 用系统桌面为应用程序背景
•android:theme=”@android:style/Theme.Wallpaper.NoTitleBar” 用系统桌面为应用程序背景,且无标题栏
•android:theme=”@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen” 用系统桌面为应用程序背景,无标题栏,全屏
•android:theme=”@android:style/Translucent” 半透明效果
•android:theme=”@android:style/Theme.Translucent.NoTitleBar” 半透明并无标题栏
•android:theme=”@android:style/Theme.Translucent.NoTitleBar.Fullscreen” 半透明效果,无标题栏,全屏
•android:theme=”@android:style/Theme.Panel”
我们来看看代码
新建一个activity 在manifest声明 然后设置Theme为自己写的style 我的叫”DialogStyle” 继承于@android:style/Theme.Dialog
设置属性
弹出的activity的xml
如果要实现自定义dialog也可以这样呦
我们来看效果
点击后弹出一个类似气泡的东西
Android平台定义的主题样式:
android:theme=”@android:style/Theme.Dialog” 将一个Activity显示为对话框模式
•android:theme=”@android:style/Theme.NoTitleBar” 不显示应用程序标题栏
•android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” 不显示应用程序标题栏,并全屏
•android:theme=”@android:style/Theme.Light” 背景为白色
•android:theme=”@android:style/Theme.Light.NoTitleBar” 白色背景并无标题栏
•android:theme=”@android:style/Theme.Light.NoTitleBar.Fullscreen” 白色背景,无标题栏,全屏
•android:theme=”@android:style/Theme.Black” 背景黑色
•android:theme=”@android:style/Theme.Black.NoTitleBar” 黑色背景并无标题栏
•android:theme=”@android:style/Theme.Black.NoTitleBar.Fullscreen” 黑色背景,无标题栏,全屏
•android:theme=”@android:style/Theme.Wallpaper” 用系统桌面为应用程序背景
•android:theme=”@android:style/Theme.Wallpaper.NoTitleBar” 用系统桌面为应用程序背景,且无标题栏
•android:theme=”@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen” 用系统桌面为应用程序背景,无标题栏,全屏
•android:theme=”@android:style/Translucent” 半透明效果
•android:theme=”@android:style/Theme.Translucent.NoTitleBar” 半透明并无标题栏
•android:theme=”@android:style/Theme.Translucent.NoTitleBar.Fullscreen” 半透明效果,无标题栏,全屏
•android:theme=”@android:style/Theme.Panel”
我们来看看代码
新建一个activity 在manifest声明 然后设置Theme为自己写的style 我的叫”DialogStyle” 继承于@android:style/Theme.Dialog
设置属性
<style name="DialogStyle" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> //设置背景为透明 <item name="android:windowNoTitle">true</item> // 设置无标题 <item name="android:backgroundDimEnabled">true</item> // 此属性可以翻译为 是否允许对话框的背景变暗?如果允许背景就变暗了。 </style>
弹出的activity的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="@drawable/bubble" android:text="@string/hello_world" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="94dp" android:layout_marginLeft="26dp" android:orientation="vertical" > </LinearLayout> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/linearLayout1" android:layout_centerHorizontal="true" android:layout_marginBottom="183dp" android:text="我是对话框" android:textSize="30sp" /> </RelativeLayout>
如果要实现自定义dialog也可以这样呦
相关文章推荐
- toolbar 和 statusbar
- Python中死锁的形成示例及死锁情况的防止
- 深入浅出Mybatis系列(六)---objectFactory、plugins、mappers简介与配置
- 百度 页面调度算法
- Android综合项目乐学成语(二)
- 传声器学习
- 贪心算法(1)——算法导论(21)
- javaWeb项目中连接MySQL出现无法加载驱动的问题
- 使用lsof恢复rm -rf删除后的文件
- 使用lsof恢复rm -rf删除后的文件
- 如何使用Dockerfile构建镜像
- suse zypper源
- STM32F769I-DISCO探索板简介
- Android图片下载缓存库picasso解析
- 百度推送始终跳转不到指定页面
- io、nio、 aio
- 重置Oracle SEQUENCE值 的存储过程
- UVa 10055 - Hashmat the Brave Warrior
- activiti教程(一)eclipse或者myEclipse安装Activiti designer插件
- 如何打jar包和运行jar包