Android Dialogs(2)最好用DialogFragment创建Dialog
Creating a Dialog Fragment
You can accomplish a wide variety of dialog designs—including custom layouts and those described in theDialogs design guide—by extending DialogFragment
and creating a AlertDialog
in the onCreateDialog()
callback method.
For example, here's a basic AlertDialog
that's managed within a DialogFragment
:
public class FireMissilesDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_fire_missiles)
.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Now, when you create an instance of this class and callshow()
on that object, the dialog appears as shown in figure 1.
Figure 1. A dialog with a message and two action buttons.
The next section describes more about using theAlertDialog.Builder
APIs to create the dialog.
Depending on how complex your dialog is, you can implement a variety of other callback methods in theDialogFragment
, including all the basic fragment lifecycle methods.
Android Dialogs(2)最好用DialogFragment创建Dialog的更多相关文章
- Android控件大全(一)——DialogFragment创建对话框
DialogFragment在android 3.0时被引入.是一种特殊的Fragment,用于在Activity的内容之上展示一个模态的对话框.典型的用于:展示警告框,输入框,确认框等等. 在Dia ...
- DialogFragment创建默认dialog
代码地址如下:http://www.demodashi.com/demo/12228.html 记得把这几点描述好咯:代码实现过程 + 项目文件结构截图 + 演示效果 前言 在我们项目的进行中不可避免 ...
- Android 官方推荐 : DialogFragment 创建对话框
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37815413 1. 概述 DialogFragment在android 3.0时 ...
- [Android Pro] Android 官方推荐 : DialogFragment 创建对话框
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37815413 1. 概述 DialogFragment在android 3.0时 ...
- 转帖:Android 官方推荐 : DialogFragment 创建对话框
转: Android 官方推荐 : DialogFragment 创建对话框 复制内容,留作备份 1. 概述 DialogFragment在android 3.0时被引入.是一种特殊的Fragment ...
- 【转】 Pro Android学习笔记(四五):Dialog(2):DialogFragment
[-] 重写onCreateView 通过onCreateView设置UI和按键反馈 信息保存 重写onCreateDialog DialogFragment的实例newInstance()已经在上一 ...
- Android Dialogs(1)Dialog简介及Dialog分类
Dialogs A dialog is a small window that prompts the user to make a decision or enter additional info ...
- Android开发:使用DialogFragment实现dialog自定义布局
使用DialogFragment实现dialog的自定义布局最大的好处是可以更好控制dialog的生命周期. TestFragment的代码: public class TestFragment ex ...
- 使用DialogFragment创建对话框总结
回调Activity中的函数 http://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents 在DialogFragme ...
随机推荐
- 【机器学习具体解释】SVM解二分类,多分类,及后验概率输出
转载请注明出处:http://blog.csdn.net/luoshixian099/article/details/51073885 CSDN−勿在浮沙筑高台 支持向量机(Support Vecto ...
- Android +NDK+eclipse+opengl ES2.0 开启深度測试
參考:https://www.opengl.org/discussion_boards/showthread.php/172736-OpenGL-ES-Depth-Buffer-Problem 环境: ...
- #include<> 和 #include""的区别
#include< file >编译程序会先到标准函数库中找文件 #include”file” 编译程序会先从当前目录中找文件 参考原文 转: 在C程序中包含文件有以下两种方法: (1)用 ...
- Web开发从零单排之一:在新浪云平台SAE上开发一个html5电子喜帖
需求描述: 本人大婚将至,女朋友说“现在都流行在微信上发电子请帖了,你不是技(cheng)术(xu)宅(yuan)嘛,不会连这个都搞不定吧” 本人嘴上说这等小事何足挂齿,但心里还是七上八下的,虽然自认 ...
- Makefile详解 (转--不错就是有点长)
概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和 professional的程序员,make ...
- Ubuntu下配置Tomcat以指定(非root)身份执行
My Blog:http://www.outflush.com/ 通常情况下.在配置Tomcat生产环境时,一般会配置Tomcat以特定的身份执行(非root).这样有利于提高安全性,防止站点被黑后的 ...
- MFC项目实战(1)文件管理器--准备篇
本程序主要实现如下功能: 程序通过左边的树形控件显示本地计算机中目录的结构,右边的列表控件则负责响应树形控件中选择的目录节点并把此节点中的所有项在列表框中显示出来,列表框支持奇偶行颜色设置,选中颜色设 ...
- CASE UPDATE
https://leetcode-cn.com/problems/swap-salary/description/ Given a table salary, such as the one belo ...
- JSON with Java
work with json-lib.jar import net.sf.json.JSONArray;import net.sf.json.JSONException;import net.sf.j ...
- HDU1260 Tickets —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Oth ...