Android 自定义对话框 showSetPwdDialog
作者:荣雪---rongsnow 发布时间:2022-04-25 22:55:00
标签:dialog,对话框,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,小编就给大家介绍这么多,希望对大家有所帮助!


猜你喜欢
- Stream简化元素计算一、接口设计从Java1.8开始提出了Stream流的概念,侧重对于源数据计算能力的封装,并且支持序列与并行两种操作
- Intellij是进行scala开发的一个非常好用的工具,可以非常轻松查看scala源码,当然用它来开发Java也是很爽的,之前一直在用sc
- 这篇文章主要介绍了Springboot如何设置静态资源缓存一年,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
- Lambda表达式类似匿名函数,简单地说,它是没有声明的方法,也即没有访问修饰符、返回值声明和方法名。Lambda允许把函数作为一个方法的参
- 相信大家对SaaS架构都有所了解,这里也不过多介绍,让我们直奔主题。技术框架springboot版本为2.3.4.RELEASE持久层采用J
- 前言Unity在运行时可以将一些物体进行合并,从而用一个绘制调用来渲染他们。这一操作,我们称之为“批处理”,能得到越好的渲染性能。Unity
- 最近做了一个项目中,其中遇到这样的需求要求图片移动到手指触碰的地方。具体实现代码如下所示:package com.example.plane
- 一、什么是桥接模式:桥接,顾名思义,就是用来连接两个部分,使得两个部分可以互相通讯,桥接模式的作用就是为被分离的抽象部分和实现部分搭桥。在现
- 编写程序,事先将所有观众姓名输入数组,然后获得数组元素的总数量,最后在数组元素中随机抽取元素的下标,根据抽取的下标获得幸运观众的姓名。思路如
- 这篇文章主要介绍了java内存泄漏与内存溢出关系解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友
- package com.imoyo.expert;import java.util.ArrayList;import android.app
- 如果要想使一个catch block能抓获多种数据类型的异常对象的话,怎么办?C++标准中定义了一种特殊的catch用法,那就是” catc
- Feign动态设置header和原理项目中用到了Feign做远程调用, 有部分场景需要动态配置header开始的做法是通过 @Request
- 简介switch的新特性可是源远流长,早在JDK 12就以预览功能被引入了,最终在JDK 14成为了正式版本的功能:JEP 361: Swi
- 本文实例为大家分享了java实现幸运抽奖功能的具体代码,供大家参考,具体内容如下本系统较为简单,未使用是什么多的算法,也未添加保存文件读取文
- 在java中,static是一个修饰符,用于修饰类的成员方法、类的成员变量,另外可以编写static代码块来优化程序性能;被static关键
- 本文实例为大家分享了java客户端登陆服务器用户名验证的具体实现代码,供大家参考,具体内容如下客户端通过键盘录入用户名,服务端对用户名进行验
- 用JAVA实现一个简单的电话本管理系统,能存储100个人的姓名、性别、年龄、电话等信息,并能对此系统进行增删改查的操作。部分代码如下:pub
- 基于servlet+jsp+jdbc的后台管理系统,包含5个模块:汽车账户部管理、租车账户部管理、汽车信息管理表、租车记录表、租车租聘表。功
- 一:背景1.讲故事最近遇到一位朋友的程序崩溃,发现崩溃点在富编辑器 msftedit 上,这个不是重点,重点在于发现他已经开启了 页堆 ,看