android的自定义dialog对话框实现
来源:互联网 发布:西门子数控仿真软件 编辑:程序博客网 时间:2024/05/17 21:43
Android自定义dialog对话框
一:自定义dialog 如何填充布局
①自定MyDialog类,在类里关联布局
<span style="white-space:pre"></span><pre name="code" class="java">public class MyDialog extends AlertDialog { Context context;public MyDialog(Context context) { super(context); this.context = context;}public MyDialog(Context context, int theme){ super(context, theme); this.context = context;}@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.layout_dialog);}}
然后,再在外面类MainActivity引用这个自定义类
Dialog dialog = new MyDialog(ActivityB.this,R.style.MyDialog);dialog.show();
//在MainActivity类里直接填充
AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this); AlertDialog dialog1 = b.create(); LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.layout_dialog, null); dialog1.setView(view, 0, 0, 0, 0); dialog1.show();
二:自定义dialog 的按钮的事件
系统的dialog ,在给对话框上的button设置事件的时候可以通过setPositiveButton()、setNegativeButton()这两个方法来实现。但是自定义的dialog就不能再用这两个方法了,可以换成setOnClickListener()方法。//setOnClickListener(android.view.View.OnClickListener object);
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_b); btn_ctrl = (Button) findViewById(R.id.btn_ctrl); tv_ticket = (TextView)findViewById(R.id.tv_ticket); btn_ctrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //初始化一个自定义的Dialog Dialog dialog = new MyDialog(ActivityB.this,R.style.MyDialog); dialog.show(); } }); tv_ticket.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder dialog1 = new AlertDialog.Builder(ActivityB.this); dialog1.getWindow().setLayout(450, 330); LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.dialog_reconn, null); dialog1.setView(view); dialog1.show(); }}); }
点完按钮之后,默认对话框不隐藏,调用dialog.dismiss()方法就可以隐藏对话框
本文由NantiJey原创总结,如需转载请标明出处 :http://blog.csdn.net/jss4j/article/details/43341767
0 0
- android的自定义dialog对话框实现
- Android底部对话框的实现(BottomSheet,自定义Dialog)
- Android多种方式实现自定义Dialog对话框
- Android多种方式实现自定义Dialog对话框
- Android多种方式实现自定义Dialog对话框
- Android中Dialog实现自定义弹出对话框
- Android实现自定义圆角对话框Dialog
- Android-对话框dialog的实现
- Android Dialog( 自定义对话框)
- Android自定义Dialog对话框
- Android 自定义Dialog对话框
- Android 自定义对话框Dialog
- Android自定义对话框(Dialog)
- 【android】自定义dialog对话框
- Android 自定义对话框dialog
- android 自定义对话框 Dialog
- Android自定义Dialog对话框
- 如何实现自定义的dialog对话框
- CodeForces 425B Sereja and Table(枚举)
- 【JSP开发】一个防盗链的WEB小例子
- iscroll5的demo,pull to refresh ,pull to load(下拉刷新,上拉加载)
- Android Toast源码分析
- POJ 1146 ID Codes (生成排列)
- android的自定义dialog对话框实现
- 玩转Bash脚本:循环结构之while循环
- Linux内核--网络栈实现分析(二)--数据包的传递过程(上)
- Android L Phone的目录结构与进程模型
- linux kernel packet receive flow(内核封包处理流程)
- 添加#pragma-
- MLE, DT, MAP简谈
- OpenLayers访问WFS跨域问题(IIS)
- Linux内核数据包处理流程-数据包接收