Android 自定义对话框 showSetPwdDialog

 更新时间:2016年03月29日 09:13:50   作者:荣雪---rongsnow  
这篇文章主要介绍了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,小编就给大家介绍这么多,希望对大家有所帮助!

相关文章

  • Android自定义View实现心形图案

    Android自定义View实现心形图案

    这篇文章主要为大家详细介绍了Android自定义View实现心形图案,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-09-09
  • Android提高之模拟信号示波器的实现

    Android提高之模拟信号示波器的实现

    这篇文章主要介绍了Android模拟信号示波器的实现方法,在Android项目开发中有一定的实用价值,需要的朋友可以参考下
    2014-08-08
  • Flutter实现仿京东商品详情底部操作栏

    Flutter实现仿京东商品详情底部操作栏

    这篇文章主要为大家详细介绍了Flutter如何仿京东实现商品详情底部操作栏,文中的示例代码讲解详细,具有一定的学习价值,感兴趣的小伙伴可以了解一下
    2023-06-06
  • Android 软键盘自动弹出与关闭实例详解

    Android 软键盘自动弹出与关闭实例详解

    这篇文章主要介绍了Android 软键盘自动弹出与关闭实例详解的相关资料,为了用户体验应该自动弹出软键盘而不是让用户主动点击输入框才弹出,这里举例说明该如何实现,需要的朋友可以参考下
    2016-12-12
  • Android 使用帧动画内存溢出解决方案

    Android 使用帧动画内存溢出解决方案

    这篇文章主要介绍了Android 使用帧动画内存溢出解决方案的相关资料,这里提供了详细的解决办法,具有参考价值,需要的朋友可以参考下
    2016-12-12
  • Android实现动态自动匹配输入内容功能

    Android实现动态自动匹配输入内容功能

    这篇文章主要为大家详细介绍了Android实现动态自动匹配输入内容功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-06-06
  • 浅谈Glide缓存key的问题

    浅谈Glide缓存key的问题

    这篇文章主要介绍了浅谈Glide缓存key的问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-04-04
  • Android开发之Location用法实例分析

    Android开发之Location用法实例分析

    这篇文章主要介绍了Android开发中Location用法,结合实例形式分析了Android使用location控件获取经纬度信息的相关操作技巧,需要的朋友可以参考下
    2016-10-10
  • android 监听SD卡文件变化的实现代码

    android 监听SD卡文件变化的实现代码

    这篇文章主要介绍了android 监听SD卡文件变化的实现代码,需要的朋友可以参考下
    2017-11-11
  • Android编程实现随机生成颜色的方法示例

    Android编程实现随机生成颜色的方法示例

    这篇文章主要介绍了Android编程实现随机生成颜色的方法,结合实例形式分析了Android使用java Random类针对随机数及颜色值相关操作技巧,需要的朋友可以参考下
    2017-08-08

最新评论