Android控件大全(一)——DialogFragment创建对话框
DialogFragment在android 3.0时被引入。是一种特殊的Fragment,用于在Activity的内容之上展示一个模态的对话框。典型的用于:展示警告框,输入框,确认框等等。
在DialogFragment产生之前,我们创建对话框:一般采用AlertDialog和Dialog。注:官方不推荐直接使用Dialog创建对话框。
先来看个DialogFragment的定义
public class MyDialogFragment extends DialogFragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);//取消标题栏
return inflater.inflate(R.layout.dialog_layout,null);
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher).setTitle("标题").setMessage("hhhhhhhhhhhhhhhh").setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
}
}
onCreateView:解析一个布局文件到Dialog中 onCreateDialog:添加一个AlertDialog到Dialog中
两个方法重写一个即可,正常人一般都不会两个都重写吧?貌似会报错。。。。。
Dialog与Activity交互
自定义一个接口,Activity实现该接口,将getActivity()强转成该接口即可。
public Dialog onCreateDialog(Bundle savedInstanceState) {
View v=LayoutInflater.from(getActivity()).inflate(R.layout.dialog_layout,null);
final EditText username= (EditText) v.findViewById(R.id.username);
final EditText password= (EditText) v.findViewById(R.id.password);
return new AlertDialog.Builder(getActivity()).setView(v).setIcon(R.mipmap.ic_launcher).setTitle("标题").setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("com.alger","po+"+which);
((ILoginListener)getActivity()).Login(username.getText().toString(),password.getText().toString());
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("com.alger","ne+"+which);
}
}).create();
}
http://blog.csdn.net/huangyabin001/article/details/30053835
Dialog位置动画等参考 :http://blog.csdn.net/maxwell0401/article/details/52336893
Android控件大全(一)——DialogFragment创建对话框的更多相关文章
- Android控件大全(二)——Toolbar
1.隐藏Actionbar 代码中设置:requestWindowFeature(Window.FEATURE_NO_TITLE) //如果Activity是继承自AppCompatActiv ...
- Android控件大全(四)——CoordinatorLayout
CoordinatorLayout 其实就是个高级的FrameLayout,用于协调子布局要使用该控件,需要再gradle中加入: compile 'com.android.support:desig ...
- Android控件大全(三)——RecyclerView
是时候用RecyclerView来替换ListView和GridView了 好处就不多说了,百度一搜一大把,来介绍下用法 先定义个适配器: public class BottomSheetAdapte ...
- [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 ...
- Android控件TextView的实现原理分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8636153 在前面一个系列的文章中,我们以窗口 ...
- Android控件常见属性
1.宽/高android:layout_width android:layout_height// 取值match_parent //匹配父控件wrap_content //自适应,根据内容 如果指定 ...
- Delphi 控件大全
delphi 控件大全(确实很全) delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org Tb97 最有名的工具条(ToolBar ...
- android控件的属性
android控件的属性 本节描述android空间的位置,内容等相关属性及属性的含义 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ( ...
随机推荐
- 避免HTML5六种错误用法
一.不要使用section作为div的替代品 人们在标签使用中最常见到的错误之一就是随意将HTML5的<section>等价于<div>--具体地说,就是直接用作替代品(用于样 ...
- setValue:forUndefinedKey
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewControlle ...
- ANT教程经典
Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一. ...
- Java多线程之线程结束清理
该事例说明了清理工作必须要放在finally块中 package Thread.Interrupting; import java.util.concurrent.TimeUnit; class Ne ...
- Gatling的进阶一
转载:http://www.51testing.com/html/10/26810-852966.html 首先 抄袭一个Gatling的介绍 Gatling是一款基于Scala 开发的高性能服务器性 ...
- play framework (一)
Playframework--像玩一样编程, 传说中有了它,放个猴子在电脑前都会编程了! http://developer.51cto.com/art/201202/320053.htm http:/ ...
- [ActionScript] AS3代码实现渐变遮罩效果
import flash.display.Shape; import flash.display.GradientType; import flash.geom.Matrix; import flas ...
- 微信企业号开发--手机删除键keyup事件无效
$('#input').keyup(function(){}); 其他的按键都是有效的,但是唯独删除按键无效. 以下方法可以解决: $('#input').bind('input propertych ...
- Django 的 CSRF 保护机制
转自:http://www.cnblogs.com/lins05/archive/2012/12/02/2797996.html 用 django 有多久,我跟 csrf 这个概念打交道就有久了. 每 ...
- nyoj 99 单词拼接
点击打开链接 单词拼接 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描述 给你一些单词,请你判断能否把它们首尾串起来串成一串. 前一个单词的结尾应该与下一个单词的道字母相同 ...