自定义Dialog以及Dialog之间跳转
2015-08-26 15:12
423 查看
需求:注册分两步完成,每一步都是一个dialog
关键点:
自定义dialog
dialog跳转样式
ps:这里实现可能不是最佳方案,因为我并没有去根据屏幕大小去设置dialog的大小
效果
自定义dialog
里面用到两个知识,一个是设置dialog的主题样式,一般都是如下设置
另外一个是dialog跳转的动画this.getWindow().setWindowAnimations(R.style.dialog_anim);
right.in的动画
left.out.xml的动画
如果我们希望可以根据屏幕大小设置dialog的宽度。通常这样做,给dialog设置onShowListener
具体里面的实现通常是这样,这个是群里一个朋友的通常写法
ps:其实刚开始想用FragmentDialog实现的,但是很多地方还是不太会处理,放弃了!
欢迎留言讨论!
关键点:
自定义dialog
dialog跳转样式
ps:这里实现可能不是最佳方案,因为我并没有去根据屏幕大小去设置dialog的大小
效果
自定义dialog
[code]/** * Created by ${wj} , * on 2015/8/11 0011. */ public class PhoneRegisterDialog extends Dialog{ private Context mContext; public PhoneRegisterDialog(Context context, int theme) { super(context, theme); this.mContext=context; } public PhoneRegisterDialog(Context context) { this(context, R.style.myDialog); this.mContext=context; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_phone_register); //点击dialog外无法关闭dialog setCancelable(false); ButterKnife.bind(this); this.getWindow().setWindowAnimations(R.style.dialog_anim); } @OnClick(R.id.next) void next(){ this.dismiss(); RegisterDialog registerDialog=new RegisterDialog(getContext()); registerDialog.show(); }
里面用到两个知识,一个是设置dialog的主题样式,一般都是如下设置
[code] <style name="myDialog" parent="Theme.AppCompat.Light.Dialog"> <!-- 背景颜色及透明程度 --> <item name="android:windowBackground">@android:color/transparent</item> <!-- 是否有标题 --> <item name="android:windowNoTitle">true</item> <!-- 是否浮现在activity之上 --> <item name="android:windowIsFloating">true</item> <!-- 是否模糊 --> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowFrame">@null</item> </style>
另外一个是dialog跳转的动画this.getWindow().setWindowAnimations(R.style.dialog_anim);
[code]<style name="dialog_anim"> <item name="android:windowEnterAnimation">@anim/right_in</item> <item name="android:windowExitAnimation">@anim/left_out</item> </style>
right.in的动画
[code]<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="800" android:toXDelta="0" android:duration="500" /> <!-- <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="800"/>--> <!--<scale android:fromXScale="0.2" android:toXScale="1.0" android:fromYScale="0.2" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="500" android:interpolator="@android:anim/accelerate_interpolator"/>--> </set>
left.out.xml的动画
[code]<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-400" android:duration="500" /> <!-- <alpha android:fromAlpha="1.0" android:toAlpha="0.5" android:duration="500"/>--> <!--<scale android:fromXScale="1.0" android:toXScale="0.2" android:fromYScale="1.0" android:toYScale="0.2" android:pivotX="50%" android:pivotY="50%" android:duration="500" android:interpolator="@android:anim/accelerate_interpolator"/>--> </set>
如果我们希望可以根据屏幕大小设置dialog的宽度。通常这样做,给dialog设置onShowListener
具体里面的实现通常是这样,这个是群里一个朋友的通常写法
ps:其实刚开始想用FragmentDialog实现的,但是很多地方还是不太会处理,放弃了!
欢迎留言讨论!
相关文章推荐
- 【POJ1751】【坑,double 不能用memset】【sqrt i j写错了】
- HDU2795 Billboard 线段树
- POJ 2115 C Looooops(单变元模线性方程)
- malloc函数、free()
- UVA - 1658 Admiral (最小费用最大流)
- 10048 - Audiophobia (Floyd)
- 架构模式及要素
- SharePoint PowerShell命令系列 (5) New-SPSite
- [TYVJ1035] 棋盘覆盖|匈牙利算法|二分图匹配
- c语言, objective code(new 1)
- 安装php时,make test报错
- 设置TableViewCell 分割线从最左侧绘制
- Apache HttpClient 4.3开发指南 实现URL重定向
- Json解析方式
- 关于 hashCode() 你需要了解的 3 件事
- Tomcat指定JAVA_HOME而不用环境变量
- 最小生成树模板
- 纯css实现三角原理,兼容IE
- hbase meta表修复
- UVA 247 - Calling Circles (Floyd)