Android自定义dialog弹出布局
来源:互联网 发布:手机计算道路软件 编辑:程序博客网 时间:2024/05/16 07:31
定义一个弹窗布局
首先定义一个dailog_set_password.xml布局文件。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#66ff6600" android:gravity="center" android:padding="10dp" android:text="设置密码" android:textColor="@color/black" android:textSize="20sp" /> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:inputType="textPassword" > </EditText> <EditText android:id="@+id/et_password_confirm" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请再次输入密码" android:inputType="textPassword" > </EditText> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn_ok" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定" /> <Button android:id="@+id/btn_cancel" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消" /> </LinearLayout></LinearLayout>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
显示这个布局文件
private void showPasswordSetDailog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog dialog = builder.create(); View view = View.inflate(this, R.layout.dailog_set_password, null); // dialog.setView(view);// 将自定义的布局文件设置给dialog dialog.setView(view, 0, 0, 0, 0);// 设置边距为0,保证在2.x的版本上运行没问题 final EditText etPassword = (EditText) view .findViewById(R.id.et_password); final EditText etPasswordConfirm = (EditText) view .findViewById(R.id.et_password_confirm); Button btnOK = (Button) view.findViewById(R.id.btn_ok); Button btnCancel = (Button) view.findViewById(R.id.btn_cancel); btnOK.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String password = etPassword.getText().toString(); String passwordConfirm = etPasswordConfirm.getText().toString(); // password!=null && !password.equals("") if (!TextUtils.isEmpty(password) && !passwordConfirm.isEmpty()) { if (password.equals(passwordConfirm)) { // Toast.makeText(HomeActivity.this, "登录成功!", // Toast.LENGTH_SHORT).show(); // 将密码保存起来 mPref.edit() .putString("password", MD5Utils.encode(password)).commit(); dialog.dismiss(); // 跳转到手机防盗页 startActivity(new Intent(HomeActivity.this, LostFindActivity.class)); } else { Toast.makeText(HomeActivity.this, "两次密码不一致!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(HomeActivity.this, "输入框内容不能为空!", Toast.LENGTH_SHORT).show(); } } }); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss();// 隐藏dialog } }); dialog.show(); }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
0 0
- 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使用(解决edittext无法弹出输入法的问题)
- android 自定义dialog弹出和消失动画
- android自定义dialog弹出框、透明背景
- android 自定义dialog弹出和消失动画
- [Android]后台Service 弹出自定义dialog
- Android Dialog 弹出框 自定义 样式
- Emgucv颜色结构
- Gamma correction 伽马校准及 matlab 实现
- Ubuntu 16.04 安装mysql并设置远程访问
- 生成树计数——SPOJ HIGH
- 网银网页制作小结
- Android自定义dialog弹出布局
- 二叉树5:平衡二叉树判断
- Android 短信的监听器
- 搭建平台区别
- SQL Sever数据库的学习
- QT写一个记事本⑦
- 递归基础之N皇后问题
- Markdown编辑器(Atom,Markdownpad2,Typora)初比较
- hdu 2230 watchcow 【图论-欧拉回路-遍历-输出路径】