DialogPlus
compile 'com.orhanobut:dialogplus:1.11@aar'
简介
- ListHolder : Items will be shown in a listview
- GridHolder : Items will be shown in a gridview
- ViewHolder : Your customized view will be shown in the content
API说明
- newDialog(Context context) 创建dialog
- setContentHolder(Holder holder) 设置holder,必要
- setContentHolder(new ViewHolder(int layoutId或View)):Use ViewHolder as content holder if you want to use a custom view for your dialog.
- setContentHolder(new ListHolder()):Use ListView as content holder, note that this is default content type.
- setContentHolder(new GridHolder(COLUMN_NUMBER)):Use GridHolder if you want to use GridView for the dialog. You must set column number.
- setContentWidth(int width) 宽,可设置为ViewGroup.LayoutParams.WRAP_CONTENT等。Set width and height for the content
- setContentHeight(int height) 高。Set width and height for the content
- setHeader(int resourceId) 头的布局或View。Set the header view using the id of the layout resource
- setFooter(int resourceId) 尾的布局或View。Set the footer view using the id of the layout resource
- setGravity(int gravity) 设置dialog的位置。android.view.Gravity中定义的位置常量都可以使用。
- setExpanded(boolean expanded) 是否可扩展,默认是false,仅适用于ListView和GridView。Enable expand animation same as Android L share dialog。default is false, only works for grid and list
- setExpanded(true, 300) 是否可扩展以及默认高度(defaultContentHeight)。Set expand animation default height
- setCancelable(boolean isCancelable) 点击外部区域是否可以取消dialog。Define if the dialog is cancelable and should be closed when back pressed or out of dialog is clicked
- setAdapter(BaseAdapter adapter) ListView或GridView时使用的adapter,ViewHolder不需要。Set Adapter, this adapter will be used to fill the content for ListHolder and GridHolder. This is required if the content holder is ListHolder or GridHolder. It is not required if the content holder is ViewHolder.
- setOnItemClickListener(OnItemClickListener listener) ListView或GridView的item的点击事件。Set an item click listener when list or grid holder is chosen. In that way you can have callbacks when one of your items is clicked
- setOnClickListener(OnClickListener listener) 点击事件。Set a global click listener to you dialog in order to handle all the possible click events. You can then identify the view by using its id and handle the correct behaviour. Only views which has id will trigger this event.
- setOnDismissListener(OnDismissListener listener):Dismiss Listener, triggered when the dialog is dismissed
- setOnCancelListener(OnCancelListener listener):Cancel Listener, triggered when the dialog is cancelled by back button or clicking outside
- setOnBackPressListener(OnBackPressListener listener):BackPress Listener, triggered when the back button is pressed
- getHolderView() 获取视图View。Get the holder view, ListView, GridView or your custom view
- getHeaderView() 获取头布局。Get the header view
- getFooterView() 获取尾布局。Get the footer view
- setMargin(left, top, right, bottom):Add margins to your dialog. They are set to 0 except when gravity is center. In that case basic margins are applied
- setOutMostMargin(left, top, right, bottom):Add margins to your outmost view which contains everything. As default they are 0 are applied
- setPadding(left, top, right, bottom):Set padding to the holder
- setInAnimation(R.anim.abc_fade_in) 进入动画。Set animation resources
- setOutAnimation(R.anim.abc_fade_out) 移除动画。Set animation resources
- setContentBackgroundResource(resource) dialog的背景色。Change content container background, as default white
- setOverlayBackgroundResource(resource) dialog以外的背景色。Change overlay container background, as default it's semi-transparent black
案例
public class MainActivity extends ListActivity {private boolean expanded = false;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);String[] array = {"DialogPlus官方demo","ViewHolder,BOTTOM","ViewHolder,TOP","ListHolder,ArrayAdapter,CENTER","ListHolder,自定义Adapter,【CENTER_HORIZONTAL】","GridHolder,自定义Adapter,CENTER_VERTICAL",};setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>(Arrays.asList(array))));}@Overrideprotected void onListItemClick(ListView l, View v, int position, long id) {expanded = !expanded;switch (position) {case 0:startActivity(new Intent(this, DialogPlusActivity.class));break;case 1:showDialogPlus(new ViewHolder(R.layout.content), null, Gravity.BOTTOM, expanded);break;case 2:showDialogPlus(new ViewHolder(R.layout.content2), null, Gravity.TOP, expanded);break;case 3:String[] array = new String[]{"包青天", "白乾涛", "baiqiantao", "0909082401"};showDialogPlus(new ListHolder(), new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, array), Gravity.CENTER, expanded);break;case 4:showDialogPlus(new ListHolder(), new SimpleAdapter(this, false), Gravity.CENTER_HORIZONTAL, expanded);break;case 5:showDialogPlus(new GridHolder(3), new SimpleAdapter(this, true), Gravity.CENTER_VERTICAL, expanded);break;}}private void showDialogPlus(Holder holder, BaseAdapter adapter, int gravity, boolean expanded) {DialogPlusBuilder builder = DialogPlus.newDialog(this).setContentHolder(holder)//必须设置,ViewHolder或ListHolder或GridHolder.setGravity(gravity)//支持三种:BOTTOM (default), TOP or CENTER.setExpanded(expanded, 600)//是否可扩展。setExpanded(true).setCancelable(true).setMargin(0, 100, 0, 0)//Add margins to your dialog. They are set to 0 except when gravity is center..setOutMostMargin(0, 0, 0, 0)//Add margins to your outmost view which contains everything. 默认为0.setContentWidth(700).setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT).setContentBackgroundResource(R.drawable.corner_background).setOverlayBackgroundResource(android.R.color.holo_blue_light).setInAnimation(com.orhanobut.dialogplus.R.anim.fade_in_center)//slide_in_top、slide_in_bottom、fade_in_center.setOutAnimation(com.orhanobut.dialogplus.R.anim.fade_out_center).setOnClickListener((dialog, view) -> Toast.makeText(this, "onClick", Toast.LENGTH_SHORT).show()).setOnItemClickListener((dialog, item, view, position) -> Toast.makeText(this, "onItemClick," + position, 0).show()).setOnDismissListener(dialog -> Toast.makeText(this, "onDismiss", Toast.LENGTH_SHORT).show()).setOnCancelListener(dialog -> Toast.makeText(this, "onCancel", Toast.LENGTH_SHORT).show()).setOnBackPressListener(dialogPlus -> Toast.makeText(this, "onBackPressed", Toast.LENGTH_SHORT).show());if (adapter != null) builder.setAdapter(adapter);//ListView或GridView时使用的adapter,ViewHolder不需要if (new Random().nextBoolean()) builder.setHeader(R.layout.header);if (new Random().nextBoolean()) builder.setFooter(R.layout.footer);builder.create().show();}}
DialogPlus的更多相关文章
- 用backbone实现的一个MVC的小demo
一.Apache配置 本实例需要使用php支持.要现在Apache中配置虚拟目录,在Apache下的httpd-vhosts.conf文件中添加如下代码 <VirtualHost *:80> ...
- Android开源项目分类汇总
目前包括: Android开源项目第一篇——个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...
- 59.Android开源项目及库 (转)
转载 : https://github.com/Tim9Liu9/TimLiu-Android?hmsr=toutiao.io&utm_medium=toutiao.io&utm_so ...
- Android主流UI开源库整理(转载)
http://www.jianshu.com/p/47a4a7b99364 标题隐含了两个层面的意思,一个是主流,另一个是UI.主流既通用,一些常规的按钮.Switch.进度条等控件都是通用控件,因此 ...
- [转]artDialog
本文转自:http://aui.github.io/artDialog/ http://aui.github.io/artDialog/doc/index.html artDialog —— 经典的网 ...
- artDialog 文档
artDialog —— 经典.优雅的网页对话框控件. 支持普通与 12 方向气泡状对话框 完善的焦点处理,自动焦点附加与回退 支持 ARIA 标准 面向未来:基于 HTML5 Dialog 的 AP ...
- Android 开源项目分类汇总(转)
Android 开源项目分类汇总(转) ## 第一部分 个性化控件(View)主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Galler ...
- android UI库
https://github.com/wasabeef/awesome-android-ui List of Android UI/UX Libraries A curated list of awe ...
- Android 开源项目分类汇总
Android 开源项目分类汇总 Android 开源项目第一篇——个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView ...
随机推荐
- The file will have its original line endings in your working directory.
在空仓库的情况下,add,出现一下问题 The file will have its original line endings in your working directory. 当报这个警告时是 ...
- C++雾中风景7:闭包
本来说好要聊一聊命名空间的,因为最近在看C++lambda表达式的内容,所以借这个机会我们来好好聊一聊C++的闭包. 1.什么是闭包? 闭包(closure)是函数式编程的重要的语法结构. 闭包的概念 ...
- CTF实验吧让我进去writeup
初探题目 两个表单,我们用burp抓包试试 这时候我们发现Cookie值里有个很奇怪的值是source,这个单词有起源的意思,我们就可以猜测这个是判断权限的依据,让我们来修改其值为1,发送得到如下显示 ...
- CAS和Synchronized
CAS compareAndSwap 原理 CAS(V,E,N) V表示要更新的变量 E表示预期值 N表示新值 (当前值和底层值一样时候,才更新) 传入的值是工作内存,底层的值是主内存,工作内 ...
- 磁盘备份工具dcfldd
磁盘备份工具dcfldd dcfldd是Kali Linux自带的一款磁盘备份工具.该工具是dd工具的增强版,更适合渗透测试和安全领域.dcfldd提供实时哈希校验功能,确保数据的安全.同时,它还 ...
- 洛谷.4252.[NOI2006]聪明的导游(提答 直径 随机化)
题目链接 随机化 暴力: 随便从一个点开始DFS,每次从之前得到的f[i]最大的子节点开始DFS.f[i]为从i开始(之前)能得到的最大答案. 要注意的是f[i]应当有机会从更小的答案更新, 9.10 ...
- Trie树 理解
Trie树的理解 Trie树又称单词查找树,字典树,是哈希树的变种: 优点在于:最大限度地减少无谓的字符串比较,查询效率比哈希高: 缺点在于:空间消耗很大: 性质 其基本性质可以归纳为: 跟结点不包括 ...
- python开发_xml.dom_解析XML文档_完整版_博主推荐
在阅读之前,你需要了解一些xml.dom的一些理论知识,在这里你可以对xml.dom有一定的了解,如果你阅读完之后. 下面是我做的demo 运行效果: 解析的XML文件位置:c:\\test\\hon ...
- vue过滤器在v2.0版本用法
vue 1.x 的写法在 vue 2.x版本已经废除 vue 1.x 写法 <body> <div id="app"> {{message | capit ...
- ThinkPHP通过类的链式继承优化空操作的实现
上篇<ThinkPHP空操作和空控制器的处理>中,在处理空操作时修改了父类Controller.class.php中代码,不到万不得已不能 修改基类控制器中的原码,此时可在子类与父类之间, ...