欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 自定义对话框 showSetPwdDialog

程序员文章站 2024-02-26 15:48:16
样式如下所示: 布局: layout   dialog_set_pwd.xml

样式如下所示:

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,小编就给大家介绍这么多,希望对大家有所帮助!