Android 自定义对话框 showSetPwdDialog

作者:荣雪---rongsnow 时间:2022-04-25 22:55:00 

样式如下所示:

Android 自定义对话框 showSetPwdDialog

布局:

layout

dialog_set_pwd.xml


<?xml version="." encoding="utf-"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EFEFEF"
android:orientation="horizontal"
android:padding="dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dialog_title_default_icon" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="dp"
android:text="设置密码"
android:textColor="@color/black"
android:textSize="sp" />
</LinearLayout>
<EditText
android:id="@+id/et_pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="dp"
android:hint="请输入密码"
android:inputType="textPassword" >
</EditText>
<EditText
android:id="@+id/et_pwd_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="dp"
android:hint="请再次输入密码"
android:inputType="textPassword" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="dp" >
<Button
android:id="@+id/btn_ok"
android:layout_width="dp"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="@drawable/btn_blue_selector"
android:text="确定"
android:layout_marginRight="dp"
android:textColor="@color/white" />
<Button
android:id="@+id/btn_cancel"
android:layout_width="dp"
android:layout_height="wrap_content"
android:layout_weight=""
android:background="@drawable/btn_white_selector"
android:text="取消"
android:textColor="@color/black" />
</LinearLayout>
</LinearLayout>

状态选择器:

drawable

btn_blue_selector.xml


<?xml version="." encoding="utf-"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/dg_btn_confirm_select" android:state_pressed="true"></item>
<item android:drawable="@drawable/dg_btn_confirm_normal"></item>
</selector>

btn_white_selector.xml


<?xml version="." encoding="utf-"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/dg_button_cancel_select" android:state_pressed="true"></item>
<item android:drawable="@drawable/dg_button_cancel_normal"></item>
</selector>

引用值

values

colors.xml


<?xml version="." encoding="utf-"?>
<resources>
<color name="black">#</color>
<color name="gray">#a</color>
<color name="white">#fff</color>
<color name="red">#f</color>
<color name="shape_setting_normal">#BDEE</color>
<color name="shape_setting_pressed">#CAD</color>
<color name="blue">#FD</color>
<color name="light_green">#f</color>
</resources>

代码:


private void showSetPwdDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = View.inflate(this, R.layout.dialog_set_pwd, null);
Button btnOk = (Button) view.findViewById(R.id.btn_ok);
Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);
final EditText etPwd = (EditText) view.findViewById(R.id.et_pwd);
final EditText etPwdConfirm = (EditText) view
.findViewById(R.id.et_pwd_confirm);
builder.setView(view);//将当前布局对象设置给dialog
final AlertDialog dialog = builder.create();
btnOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String pwd = etPwd.getText().toString().trim();
String pwdConfirm = etPwdConfirm.getText().toString().trim();
if (TextUtils.isEmpty(pwd) || TextUtils.isEmpty(pwdConfirm)) {
ToastUtils.showToast(getApplicationContext(), "输入内容不能为空!");
} else {
if (pwd.equals(pwdConfirm)) {
System.out.println("登录成功!");
//将密码保存在本地sp
PrefUtils.putString(getApplicationContext(),
GlobalConstants.PREF_PASSWORD,
MDUtils.getMd(pwd));
dialog.dismiss();
enterLostAndFindPage();
} else {
ToastUtils.showToast(getApplicationContext(),
"两次密码不一致!");
}
}
}
});
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}

有关Android 自定义对话框 showSetPwdDialog,小编就给大家介绍这么多,希望对大家有所帮助!

标签:dialog,对话框,showSetPwdDialog
0
投稿

猜你喜欢

  • Python安装Jupyter Notebook配置使用教程详解

    2023-08-31 02:52:03
  • Android应用中炫酷的横向和环形进度条的实例分享

    2023-09-21 17:33:08
  • 如何使用MybatisPlus快速进行增删改查详解

    2023-11-03 06:58:13
  • Java 读写锁源码分析

    2021-08-31 01:48:54
  • String.replaceAll方法详析(正则妙用)

    2022-02-12 03:07:29
  • WinForm下 TextBox只允许输入数字的小例子

    2023-08-02 15:34:14
  • 浅谈抛出异常和捕获异常的一些区别

    2023-10-19 15:25:24
  • Java多态中动态绑定原理解析

    2021-08-01 06:39:23
  • springmvc 分页查询的简单实现示例代码

    2022-01-09 11:08:22
  • Android之获取手机内部及sdcard存储空间的方法

    2022-11-11 13:10:18
  • 解析Nacos的API居然存在这么严重的漏洞

    2022-05-29 08:17:52
  • C#中[]的几种用法示例代码

    2022-03-20 05:50:46
  • Spring Utils工具类常用方法实例

    2023-05-01 05:37:37
  • JavaWeb中获取表单数据及乱码问题的解决方法

    2021-11-21 11:03:53
  • 详解JAVA 时间处理相关类

    2022-11-07 03:12:36
  • java中删除 数组中的指定元素方法

    2023-02-02 12:45:59
  • Idea运行单个main方法,不编译整个工程的问题

    2021-09-06 09:57:22
  • Java Fluent Mybatis实战之构建项目与代码生成篇下

    2023-11-24 10:59:52
  • 深入理解Java中观察者模式与委托的对比

    2023-10-30 18:00:03
  • Android N多窗口支持

    2022-08-08 19:27:37
  • asp之家 软件编程 m.aspxhome.com