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

时间: 2024-07-31 03:32:56

Android 自定义对话框 showSetPwdDialog的相关文章

Android 自定义对话框 showSetPwdDialog_Android

样式如下所示: 布局: 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=&

Android自定义对话框Dialog的简单实现

本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中. 首先来看一下效果图: 首先是activity的界面 点击了上述图片的按钮后,弹出对话框: 点击对话框的确定按钮: 点击对话框的取消按钮: 下面来说一下具体实现步骤: 第一步:设置Dialog的样式(一般项目都可以直接拿来用):style.xml中 <!--自定义Dialog背景全透明无边框theme--> <style name="MyDialo

Android自定义对话框Dialog

本文简单介绍自定义对话框Dialog的使用,代码和结构都非常简单,目的是能够快速使用自定义对话框,在本文中不具体讲解对话框的高级使用. 实现步骤 首先需要自己在我们的.xml文件中自己构建布局 布局文件做好之后,我们可以在style文件下自己定义布局的样式 前两步都做好之后,我开始在写java文件 具体实现过程 1.   xml文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns

Android自定义等待对话框_Android

最近,看了好多的APP的等待对话框,发现自己的太lower,于是就研究了一番,最后经过苦心努力,实现一个. 自定义一个LoadingIndicatorView(extends View )类 编写values/attrs.xml,在其中编写styleable和item等标签元素 在布局文件中LoadingIndicatorView使用自定义的属性(注意namespace) 在LoadingIndicatorView的构造方法中通过TypedArray获取 描述就提供这些,一下是代码的展示,非常的

Android简明开发教程十八:自定义对话框Transform

Android自带的AlertDialog,ProgressDialog,DatePickerDialog,TimePickerDialog 可以用于简单的对话框显示.当还是有 这些对话框不能满足应用需要的时候,这时就可以使用一些自定 义的对话框.有多种方法可以实现自定义对话框.一是使用Activity作为Dialog,可以通过设置Activity显示Dialog风格,使得 该Activity在外观上和Dialog一致:显示在其它Activity前面 且半透明. <Activity androi

Android使用setCustomTitle()方法自定义对话框标题_Android

Android有自带的对话框标题,但是不太美观,如果要给弹出的对话框设置一个自定义的标题,使用AlertDialog.Builder的setCustomTitle()方法. 运行效果如下,左边是点击第一个按钮,弹出Android系统自带的对话框(直接用setTitle()设置标题):右边是点击第二个按钮,首先inflate一个View,然后用setCustomTitle()方法把该View设置成对话框的标题. 定义一个对话框标题的title.xml文件: <?xml version="1.

android中怎么实现一个自定义对话框

问题描述 android中怎么实现一个自定义对话框 android界面中,单击EditText弹出一个时间对话框, 解决方案 1.可以自定义对话框的布局 2.新建一个activity 设置android:theme="@style/mydialog" parent="@android:style/Theme.Dialog" ><br> <item name="android:windowNoTitle">true&l

ANDROID中自定义对话框AlertDialog使用示例_Android

在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式.AlertDialog中定义的一些对话框往往无法满足我们关于对话框的需求,这时我们就需要通过自定义对话框VIEW来实现需求,这里我自定义一个登陆的提示对话框,效果图显示如下: Layout(alertdialog自定义登陆按钮)界面代码: <?xml version="1.0" en

android中怎么设置一个日期的自定义对话框

问题描述 android中怎么设置一个日期的自定义对话框 在android界面中,单击EditText,弹出一个日期对话框.应该怎么弄?求大神帮忙!!! 解决方案 参考android 点击EditText 弹出日期选择器DatePickerDialog 解决方案二: 上面的答案有帮助吗?如果还有问题,请提出来,如果对答案满意,请顶一下,并标记为采纳答案,谢谢!