DialogPlus

项目地址:https://github.com/orhanobut/dialogplus

Demo地址:https://github.com/baiqiantao/DialogPlusTest

  1. compile ‘com.orhanobut:dialogplus:[email protected]‘

简介

Dialogplus是一个非常简单易用的Dialog对话框控件,但是这并不是一个Dialog或AlertDialog或DialogFragment的衍生类,而是通过DecorView进行插入,所以他是一个阻塞式的窗口,也就是说这个Dialog一打开,其他控件就接收不到焦点了。

Advanced dialog solution for android

DialogPlus provides 3 content types:

  • 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

案例

  1. public class MainActivity extends ListActivity {
  2. private boolean expanded = false;
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. String[] array = {"DialogPlus官方demo",
  6. "ViewHolder,BOTTOM",
  7. "ViewHolder,TOP",
  8. "ListHolder,ArrayAdapter,CENTER",
  9. "ListHolder,自定义Adapter,【CENTER_HORIZONTAL】",
  10. "GridHolder,自定义Adapter,CENTER_VERTICAL",};
  11. setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>(Arrays.asList(array))));
  12. }
  13. @Override
  14. protected void onListItemClick(ListView l, View v, int position, long id) {
  15. expanded = !expanded;
  16. switch (position) {
  17. case 0:
  18. startActivity(new Intent(this, DialogPlusActivity.class));
  19. break;
  20. case 1:
  21. showDialogPlus(new ViewHolder(R.layout.content), null, Gravity.BOTTOM, expanded);
  22. break;
  23. case 2:
  24. showDialogPlus(new ViewHolder(R.layout.content2), null, Gravity.TOP, expanded);
  25. break;
  26. case 3:
  27. String[] array = new String[]{"包青天", "白乾涛", "baiqiantao", "0909082401"};
  28. showDialogPlus(new ListHolder(), new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, array)
  29. , Gravity.CENTER, expanded);
  30. break;
  31. case 4:
  32. showDialogPlus(new ListHolder(), new SimpleAdapter(this, false), Gravity.CENTER_HORIZONTAL, expanded);
  33. break;
  34. case 5:
  35. showDialogPlus(new GridHolder(3), new SimpleAdapter(this, true), Gravity.CENTER_VERTICAL, expanded);
  36. break;
  37. }
  38. }
  39. private void showDialogPlus(Holder holder, BaseAdapter adapter, int gravity, boolean expanded) {
  40. DialogPlusBuilder builder = DialogPlus.newDialog(this)
  41. .setContentHolder(holder)//必须设置,ViewHolder或ListHolder或GridHolder
  42. .setGravity(gravity)//支持三种:BOTTOM (default), TOP or CENTER
  43. .setExpanded(expanded, 600)//是否可扩展。setExpanded(true)
  44. .setCancelable(true)
  45. .setMargin(0, 100, 0, 0)//Add margins to your dialog. They are set to 0 except when gravity is center.
  46. .setOutMostMargin(0, 0, 0, 0)//Add margins to your outmost view which contains everything. 默认为0
  47. .setContentWidth(700)
  48. .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
  49. .setContentBackgroundResource(R.drawable.corner_background)
  50. .setOverlayBackgroundResource(android.R.color.holo_blue_light)
  51. .setInAnimation(com.orhanobut.dialogplus.R.anim.fade_in_center)//slide_in_top、slide_in_bottom、fade_in_center
  52. .setOutAnimation(com.orhanobut.dialogplus.R.anim.fade_out_center)
  53. .setOnClickListener((dialog, view) -> Toast.makeText(this, "onClick", Toast.LENGTH_SHORT).show())
  54. .setOnItemClickListener((dialog, item, view, position) -> Toast.makeText(this, "onItemClick," + position, 0).show())
  55. .setOnDismissListener(dialog -> Toast.makeText(this, "onDismiss", Toast.LENGTH_SHORT).show())
  56. .setOnCancelListener(dialog -> Toast.makeText(this, "onCancel", Toast.LENGTH_SHORT).show())
  57. .setOnBackPressListener(dialogPlus -> Toast.makeText(this, "onBackPressed", Toast.LENGTH_SHORT).show());
  58. if (adapter != null) builder.setAdapter(adapter);//ListView或GridView时使用的adapter,ViewHolder不需要
  59. if (new Random().nextBoolean()) builder.setHeader(R.layout.header);
  60. if (new Random().nextBoolean()) builder.setFooter(R.layout.footer);
  61. builder.create().show();
  62. }
  63. }

2017-6-16

null

时间: 2024-10-13 12:36:37

DialogPlus的相关文章

用backbone实现的一个MVC的小demo

一.Apache配置 本实例需要使用php支持.要现在Apache中配置虚拟目录,在Apache下的httpd-vhosts.conf文件中添加如下代码 <VirtualHost *:80> DocumentRoot "D:/htdocs/backbone_demo" ServerName www.backbonedemo.cn </VirtualHost> 在windows的hosts文件中添加配置,hosts文件的位置在c:\windows\system32

android源码大放送(实战开发必备),免费安卓demo源码,例子大全文件详细列表

免费安卓demo源码,例子大全文件详细列表 本列表源码永久免费下载地址:http://www.jiandaima.com/blog/android-demo 卷 yunpan 的文件夹 PATH 列表 卷序列号为 0000-73EC E:. │ jiandaima.com文件列表生成.bat │ 例子大全说明.txt │ 本例子永久更新地址~.url │ 目录列表2016.03.10更新.txt │ ├─前台界面 │ ├─3D标签云卡片热门 │ │ Android TagCloudView云标签

前段js的各种弹出框

artDialog 首页 > 文档与示例 artDialog —— 经典的网页对话框组件,内外皆用心雕琢. 支持普通与 12 方向气泡状对话框 完善的焦点处理,自动焦点附加与回退 支持 ARIA 标准 面向未来:基于 HTML5 Dialog 的 API 支持标准与模态对话框 丰富且友好的编程接口 能自适应内容尺寸 仅 4kb (gzip) 文档导航 引入 artDialog 快速参考 普通对话框 模态对话框 气泡浮层 添加按钮 控制对话框关闭 给对话框左下脚添加复选框 阻止对话框关闭 不显示关

Android 开源项目分类汇总

目前包括: Android 开源项目第一篇--个性化控件(View)篇  包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView.FlipView.ColorPickView.GraphView.UI Style.其他Android 开源项目第二篇--工具库篇  包括依赖注入.图片缓存.网络请求.数据库 ORM 工具包.Andro

Android常用酷炫控件(开源项目)github地址汇总

转载一个很牛逼的控件收集贴... 第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView.FlipView.ColorPickView.GraphView.UI Style 等等. 一.ListView android-pulltorefresh一个强大的拉动

artDialog

artDialog 首页 > 文档与示例 artDialog —— 经典.优雅的网页对话框控件. 支持普通与 12 方向气泡状对话框 完善的焦点处理,自动焦点附加与回退 支持 ARIA 标准 面向未来:基于 HTML5 Dialog 的 API 支持标准与模态对话框 丰富且友好的编程接口 能自适应内容尺寸 仅 4kb (gzip) 文档导航 引入 artDialog 快速参考 普通对话框 模态对话框 气泡浮层 添加按钮 控制对话框关闭 给对话框左下脚添加复选框 点按钮不关闭对话框 不显示关闭按钮

最新最全的 Android 开源项目合集

原文链接:https://github.com/opendigg/awesome-github-android-ui 在 Github 上做了一个很新的 Android 开发相关开源项目汇总,涉及到 Android 开发的方方面面,基本很全了.对 Android 开发感兴趣的欢迎 Star ,后续也会定期维护更新这个列表.当然,你也可以去 opendigg 上查看. -- 由欧戈分享 awesome-github-android-ui 是由OpenDigg整理并维护的安卓UI相关开源项目库集合.

Android 开源项目android-open-project解析之(四) ColorPickView,GraphView,UI Style,Other

十三.ColorPickView ColorPickerView 颜色选择器,支持PopupWindows或新的Activity中打开 项目地址:https://code.google.com/p/color-picker-view/ 效果图: HoloColorPicker 颜色选择器 项目地址:https://github.com/LarsWerkman/HoloColorPicker Demo地址:https://docs.google.com/file/d/0BwclyDTlLrdXRz

[转]artDialog

本文转自:http://aui.github.io/artDialog/ http://aui.github.io/artDialog/doc/index.html artDialog —— 经典的网页对话框组件,内外皆用心雕琢. 支持普通与 12 方向气泡状对话框 完善的焦点处理,自动焦点附加与回退 支持 ARIA 标准 面向未来:基于 HTML5 Dialog 的 API 支持标准与模态对话框 丰富且友好的编程接口 能自适应内容尺寸 仅 4kb (gzip) 文档导航 引入 artDialo