android自定义弹出对话框,使用FlyDialog实现自定义Android弹窗对话框
前言
学习的时候要用到弹窗,但是又觉得i同自带的弹窗样式有点不太美观,搜索资料后发现了FlycoDialog这个开源库,效果很好,而且实现起来也比较方便。
先列举一些比较好看的效果:
NormalListDialog
ActionSheetDialog
这篇文章主要来讲一下他的自定义弹出对话框。
使用
添加依赖
compile 'com.flyco.dialog:FlycoDialog_Lib:1.3.2@aar'
编写一个要显示的弹窗的布局
android:layout_width="match_parent" android:layout_height="match_parent">
android:id="@+id/iv_customize"
android:layout_width="278dp"
android:layout_height="392dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
android:id="@+id/ad_back"
android:layout_width="278dp"
android:layout_height="45dp"
android:layout_alignRight="@id/iv_customize"
android:layout_alignTop="@id/iv_customize"
android:background="#01ffffff"/>
这是一个非常简单的界面,大的ImageView用来展示图片,小的ImageView用来点击然后使弹窗消失。
编写弹窗的逻辑代码
public class CustomBaseDialog extends BaseDialog {
private Context context;
private ImageView iv_customize;
private ImageView back;
public CustomBaseDialog(Context context) {
super(context);
this.context = context;
}
//该方法用来出来数据初始化代码
@Override
public View onCreateView() {
widthScale(0.85f);
//填充弹窗布局
View inflate = View.inflate(context, R.layout.dialog_customize, null);
//用来放整个图片的控件
iv_customize = (ImageView) inflate.findViewById(R.id.iv_customize);
//放在透明部分和错号上的隐形控件,用来点击使弹窗消失
back = (ImageView) inflate.findViewById(R.id.back);
//用来加载网络图片,填充iv_customize控件,注意要添加网络权限,和Picasso的依赖和混淆
Picasso.with(context)
.load("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png")
.into(iv_customize);
return inflate;
}
//该方法用来处理逻辑代码
@Override
public void setUiBeforShow() {
//点击弹窗相应位置,处理相关逻辑。
iv_customize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,"哈哈",Toast.LENGTH_SHORT).show();
//处理完逻辑关闭弹框的代码
dismiss();
}
});
//点×关闭弹框的代码
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//关闭弹框的代码
dismiss();
}
});
}
}
编写启动弹窗的代码
CustomBaseDialog customBaseDialog = new CustomBaseDialog(this);
customBaseDialog.onCreateView();
customBaseDialog.setUiBeforShow();
//点击空白区域能不能退出
customBaseDialog.setCanceledOnTouchOutside(true);
//按返回键能不能退出
customBaseDialog.setCancelable(true);
customBaseDialog.show();
如果要处理一些比较复杂的逻辑可以通过CustomBaseDialog的构造方法往弹窗中传值,如下:
弹窗逻辑代码的构造方法:
public CustomBaseDialog(Context context, String general_Info, String love_Info, String iv_url) {
super(context);
this.context = context;
this.love_Info = love_Info;
this.iv_url = iv_url;
this.general_Info = general_Info;
}
启动时再传入数据即可
CustomBaseDialog customBaseDialog = new CustomBaseDialog(MainActivity.this, general_Info, love_Info, pic_url);
customBaseDialog.onCreateView();
customBaseDialog.setUiBeforShow();
//点击空白区域能不能退出
customBaseDialog.setCanceledOnTouchOutside(true);
//按返回键能不能退出
customBaseDialog.setCancelable(true);
customBaseDialog.show();
这个开源库还有非常非常多的动画效果,可以好好探索。
android自定义弹出对话框,使用FlyDialog实现自定义Android弹窗对话框相关推荐
- android popupwindowd弹出时后面变灰色,自定义PopupWindow弹出后背景灰色状态
最近有做fragment里弹出自定义popupWindow, fragment里面调用: // 点击加号按钮 @Click protected void ll_add_pharmacy() { mPo ...
- Android对弹出输入法界面影响app界面布局
Android中弹出输入法界面不影响app界面布局 默认情况下,输入法弹出的时候,原来的view会被挤扁.有些应用不想被挤,它们可以接受被输入法view覆盖在上面.这时候需要在AndroidManif ...
- android弹出框自定义按钮,安卓(kotlin)自定义弹出框
在安卓开发中,我们经常会遇到这种情况,就是可爱的UI们设计了一套属于我们自己风格的弹出框,为了彰显我们自己的风格,使用自动的dialog当然满足不了我们的需求,所以还是得这基础上写出我们自己的提示框, ...
- JavaScript - JavaScript自定义弹出对话框
本脚本使用自定义的浮动窗口替代浏览器自己的对话框,效果非常不错.包含Error | Warning | Success | Prompt 四个对话框窗口 兼容性:IE6+ FireFox2+ Oper ...
- android 自定义 popupwindow,Android自定义弹出窗口PopupWindow使用技巧
PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(View contentView, int widt ...
- android自定义弹出框样式实现
前言: 做项目时,感觉Android自带的弹出框样式比较丑,很多应用都是自己做的弹出框,这里也试着自己做了一个. 废话不说先上图片: 实现机制 1.先自定义一个弹出框的样式 2.自己实现CustomD ...
- Android Dialog弹出方式动画
//自定义Dialogclass myDialog extends Dialog{private Window window = null;public myDialog(Context contex ...
- 微信小程序项目实战知识点总结(swiper组件自适应高度,自定义弹出层,悬浮按钮,虚拟键盘)...
1.小程序 swiper 组件默认高度150px,并且如果子元素过高,swiper不会自适应高度 height:100vh; 2.微信小程序自定义弹出层,参考网址:https://blog.cs ...
- Qt总结:QMessageBox(原生态弹出框及究极超nice封装自定义弹出框)
一.前言 在Qt中经常需要弹出窗口,QMessageBox可以实现此功能,一共有三种窗口,information, question, 和 warning,critical, about分别对应感叹号 ...
最新文章
- ORACLE安装参数修改
- 4028: [HEOI2015]公约数数列
- python3 mysql报警日志_Python监听MySQL日志
- LevelDB 源码剖析(三)公共基础:内存管理、数值编码、Env家族、文件操作
- linux 链接 文件,聊聊 Linux 里的文件链接
- POJ2184 Cow Exhibition(DP:变种01背包)
- css 获取屏幕宽度_设备像素、设备独立像素、CSS像素、分辨率、PPI、devicePixelRatio 的区别...
- 串口服务器信号连接不上,使用RS485串口服务器经常遇到的问题
- 西门子大中华区总裁兼CEO赫尔曼:智能自主制造将重塑工业格局!
- web测试软件act,使用ACT对Web程序进行性能容量测试.doc
- ios苹果手机 uniapp长按识别二维码图片白色背景问题
- web前端腾讯外包面试记录
- variance和variation的区别
- 阿里云短信服务 手机验证码
- Room框架学习、使用
- arnold ass standin 代理模型批量查询 与替换工具发布1.0
- 区块链 - 牵一发而动全身的链式结构
- PLC通讯实现-C#实现西门子PLC以太网通讯Sharp7(六)
- 42步进电机转速力矩曲线_步进电机的力矩与转速
- Mac中禁用向日葵(Oray)控制端自启动