Android自定义对话框
来源:互联网 发布:手机扫描录入软件 编辑:程序博客网 时间:2024/06/02 05:24
1.作用
自定义弹出的对话框,方便对对话框进行各种操作和美化对话框
2.实现步骤
2.1在layout目录下创建dialog_setup.xml文件2.2在创建对话框的位置引用自定义的对话框
3.效果图
4.具体实现
4.1 在layout目录下创建dialog_setup.xml文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:background="#ffffff" > <TextView android:layout_width="match_parent" android:layout_height="50dp" android:background="#8866ff00" android:gravity="center" android:text="设置密码" android:textColor="#000000" android:textSize="18sp" /> <EditText android:hint="请输入密码" android:textColor="#000000" android:id="@+id/et_password" android:layout_width="280dp" android:layout_height="wrap_content" android:inputType="textPassword" > </EditText> <EditText android:hint="请确认密码" android:textColor="#000000" android:id="@+id/et_password_confirm" android:layout_width="280dp" android:layout_height="wrap_content" android:inputType="textPassword" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn_ok" android:textColor="#000000" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="确定" /> <Button android:id="@+id/btn_cancel" android:textColor="#000000" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消" /> </LinearLayout></LinearLayout>
4.2 在创建对话框的位置引用自定义的对话框
protected void showSetupDialog() { AlertDialog.Builder builder=new Builder(this); View view=View.inflate(getApplicationContext(), R.layout.dialog_setup, null); // 加载控件 final EditText et_password=(EditText) view.findViewById(R.id.et_password); final EditText et_password_confirm=(EditText) view.findViewById(R.id.et_password_confirm); Button btn_ok=(Button) view.findViewById(R.id.btn_ok); Button btn_cancel=(Button) view.findViewById(R.id.btn_cancel); // 取消按钮的点击事件 btn_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 隐藏dialog dialog.dismiss(); } }); btn_ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String password=et_password.getText().toString().trim(); String password_confirm=et_password_confirm.getText().toString().trim(); if(!TextUtils.isEmpty(password)){ if(password.equals(password_confirm)){ // 密码设置成功 Editor edit = sp.edit(); edit.putString("password", MD5Utils.digest(password)); edit.commit(); dialog.dismiss(); //edit.apply() }else{ Toast.makeText(getApplicationContext(), "两次密码不一致", 0).show(); } }else{ Toast.makeText(getApplicationContext(), "密码不能为空", 0).show(); } } }); builder.setView(view);// 设置dialog显示的view对象 dialog = builder.create(); dialog.show();}
兼容低版本 **
//builder.setView(view);// 设置dialog显示的view对象dialog = builder.create();dialog.setView(view, 0, 0, 0, 0);dialog.show();
0 0
- android中的对话框:自定义对话框
- Android Dialog( 自定义对话框)
- android 自定义对话框
- android自定义对话框
- Android自定义对话框
- android 自定义对话框
- Android自定义Dialog对话框
- android自定义大小对话框
- android自定义对话框
- Android自定义对话框
- android 自定义对话框
- android 自定义对话框
- android自定义对话框
- android 自定义对话框动画
- Android弹出自定义对话框
- android自定义对话框
- android 自定义对话框
- Android自定义对话框
- When to use __new__ vs __init__
- js自定义对象
- (五)Spark源码理解之BroadcastManager
- [刷题]Permutations
- Android XML解析技术——DOM
- Android自定义对话框
- zbox的测试例——selectAll+selectInverse
- 漫画:应对海量数据 实现灵活拓展云存储
- JNI中使用LOGCAT 进行Debug
- iOS "xxx" is missing from working copy
- MS SQLserver mysql
- 第二周上机项目1 旱冰场造价
- CentOS 7通过yum安装fcitx五笔输入法
- C++中关于内部与外部函数