自定义AlertDialog的创建和使用
来源:互联网 发布:时间轴源码 编辑:程序博客网 时间:2024/05/22 05:03
- 填充视图
View v = myActivity.this.getLayoutInflater().inflate( R.layout.dialog_nickname, null);
其中R.layout.dialog_nickname是已经写好的布局文件,想要显示什么就再这个布局文件中添加控件。
如果想要获得R.layout.dialog_nickname里的控件,就用
v.findViewById(R.id.input_et);
- 创建dialog
new AlertDialog.Builder(PersonInfoActivity.this) .setView(v) // .setTitle("编辑昵称") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (TextUtils.isEmpty(dialogNickName.getText())) { showToast("昵称不能为空"); } else { // 如果点击确定时dialog里的昵称和原来的昵称 if (!nickNameInfo_tv.getText().equals( dialogNickName.getText())) { nickNameInfo_tv.setText(dialogNickName .getText()); } } } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create().show();
这样点击确定按钮就能更改TextView里的昵称了
此外还有一些其他方法比较常用的
setTitle(title)
设置对话框的标题
dialog.setCanceledOnTouchOutside(false);
//设置点击Dialog外部任意区域关闭Dialog,false为不会关闭
LayoutInflater inflater = LayoutInflater.from(mContext);
//获得填充器
View dialogView = inflater.inflate(R.layout.dialog, null);
//填充视图到dialogView
0 0
- 自定义AlertDialog的创建和使用
- AlertDialog使用和自定义
- alertDialog的自定义style和使用(Android)
- alertDialog的自定义style和使用(Android)
- 使用自定义视图的AlertDialog
- AlertDialog使用自定义的布局
- Android之使用AlertDialog类和AlertDialog.Builder类创建带取消,确定,中立的对话框
- 创建自定义AlertDialog
- DialogFragment和AlertDialog的使用
- 自定义AlertDialog和一般的Dialog
- 自定义AlertDialog的位置和大小确定
- AlertDialog的使用(二):分别创建
- 使用AlertDialog创建对话框的大致步骤
- (自定义)AlertDialog使用
- 自定义ListView和AlertDialog
- 自定义PopupWindow和AlertDialog
- 使用AlertDialog创建对话框
- 使用AlertDialog创建对话框
- 接口和抽象类
- NTFS for Mac如何安装
- Fiddler使用教程
- 单例模式
- C语言常见面试题(经典中的经典)
- 自定义AlertDialog的创建和使用
- NTFS For Mac 破解版下载
- SVM介绍
- 悟空学Linux专栏----第5篇
- Markdown
- android 签名查看的命令
- 门面(Facade)模式
- 云计算平台最核心的五项技术
- Contains Duplicate II