Android 注册页面 设置显示或者隐藏密码 和 点击获取验证码倒计时60s
2016-07-05 21:24
686 查看
在Android开发时候 肯定遇到注册输入密码 、验证码之类的问题
用户登录或者是注册页面肯定都有输入密码的小框框
这时候就需要用到 显示或者隐藏密码了
验证码稍微复杂一点 需要点击后背景变灰 字也变成了倒计时
话不多说 直接代码
xml文件
android:password="true"//这个属性是让输入的密码不可见。。。但是这个属性已经过时了
下面是逻辑代码
这个方法就搞定哦
下面是获取验证码倒计时
直接上代码 xml文件
逻辑代码
好了 是不是特别的简单
觉得不错的帮忙点个赞 谢谢
用户登录或者是注册页面肯定都有输入密码的小框框
这时候就需要用到 显示或者隐藏密码了
验证码稍微复杂一点 需要点击后背景变灰 字也变成了倒计时
话不多说 直接代码
xml文件
<EditText android:password="true" android:maxLength="16" android:inputType="textPassword" android:id="@+id/set_password" android:layout_width="match_parent" android:layout_height="80px" android:layout_marginTop="20px" android:background="@color/colorWhite" /> <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示密码" android:textSize="24px"/>
android:password="true"//这个属性是让输入的密码不可见。。。但是这个属性已经过时了
android:inputType="textPassword"//这个属性才是正确用运
下面是逻辑代码
EditText password = (EditText) findViewById(R.id.set_password);
checkBox = (CheckBox) findViewById(R.id.checkBox1);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { //如果选中,显示密码 password.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else { //否则隐藏密码 password.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } });
这个方法就搞定哦
下面是获取验证码倒计时
直接上代码 xml文件
<EditText android:maxLength="6" android:layout_weight="2" android:id="@+id/verification" android:layout_width="0dp" android:layout_height="match_parent" android:background="@color/colorWhite"/> <TextView android:gravity="center" android:id="@+id/send_verification" android:textColor="@android:color/white" android:background="@mipmap/yanzhengcodepressbutton" android:text="@string/send_verification" android:textSize="26px" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" />
逻辑代码
EditText verification = (EditText) findViewById(R.id.verification);
TextView sendVerification = (TextView) findViewById(R.id.send_verification);
String verifications = verification.getText().toString();
private Boolean flag = true;
if (flag == true) {//点进来时候判断是否 能够点击 flag=false; sendVerification.setEnabled(false);//倒计时结束前不让点击 //按键背景颜色变灰 sendVerification.setBackgroundResource(R.color.light_grey); //倒计时我在这里倒计时60s final CountDownTimer timer = new CountDownTimer(60000, 1000) { @Override public void onTick(long millisUntilFinished) { //替换按钮上的字 sendVerification.setText(millisUntilFinished / 1000 + "秒重新发送"); } @Override public void onFinish() {//倒计时结束时候 //给按钮的字换回来 sendVerification.setText("发送验证码"); //背景也换回来 sendVerification.setBackgroundResource(R.mipmap.yanzhengcodepressbutton); flag = true;//标记变为可用状态 sendVerification.setEnabled(true);//按钮可点击了 } }.start();
}
好了 是不是特别的简单
觉得不错的帮忙点个赞 谢谢
相关文章推荐
- Android自定义View初步(一)
- Java/android中解析xml的3种方法
- Android设计模式之观察者模式 Observer
- Android设计模式之观察者模式 Observer
- Android设计模式之观察者模式 Observer
- Android设计模式之观察者模式 Observer
- 安卓之design系列(二)
- EditText属性设置
- Native.js for Android
- Android 获取固定的dip、dp值
- 关于Android Context------你应该心里稍微有个数
- Android通讯录,使用批处理,速度很快
- Java4Android知识点梳理
- Android 基础之RelativeLayout
- 熟悉Android-handler机制
- 开源android-crop裁剪库的bug并修复
- Android Studio NDK开发--JNI编程
- Android判断输入的是电话号码,判断字符串长度,以及只允许数字输入
- Android逆向之旅---动态方式破解apk进阶篇(IDA调试so源码)
- Activity的启动模式和生命周期 android初学者必看;