android 登录保存密码,android 如何实现登陆界面的记住密码功能
今天 写了一个有关登录记住密码的列子 其实这个例子的关键使用到了AutoCompleteTextView 以及sharedPreference的两个关键知识点,大家知道 AutoCompleteTextView 他的默认字体颜色以及背景颜色都是白色 所以我们要对下拉菜单的textview进行颜色定义区分好 我们先来看怎么区分的
list_item.xml
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#000">
接下来是重点哦
/*author: conowen
* date: 2012.4.2
*
*/
package com.hipikids.remeber;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class RemeberPwdActivity extends Activity {
AutoCompleteTextView cardNumAuto;
EditText passwordET;
Button logBT;
CheckBox savePasswordCB;
SharedPreferences sp;
String cardNumStr;
String passwordStr;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_remeber_pwd);
cardNumAuto = (AutoCompleteTextView) findViewById(R.id.cardNumAuto);
passwordET = (EditText) findViewById(R.id.passwordET);
logBT = (Button) findViewById(R.id.logBT);
sp = this.getSharedPreferences("passwordFile", MODE_PRIVATE);
savePasswordCB = (CheckBox) findViewById(R.id.savePasswordCB);
savePasswordCB.setChecked(true);// 默认为记住密码
cardNumAuto.setThreshold(1);// 输入1个字母就开始自动提示
passwordET.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
// 隐藏密码为InputType.TYPE_TEXT_VARIATION_PASSWORD,也就是0x81
// 显示密码为InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,也就是0x91
cardNumAuto.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String[] allUserName = new String[sp.getAll().size()];// sp.getAll().size()返回的是有多少个键值对
allUserName = sp.getAll().keySet().toArray(new String[0]);
// sp.getAll()返回一张hash map
// keySet()得到的是a set of the keys.
// hash map是由key-value组成的
ArrayAdapter adapter = new ArrayAdapter(
RemeberPwdActivity.this,
R.layout.list_item,
allUserName);
cardNumAuto.setAdapter(adapter);// 设置数据适配器
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
passwordET.setText(sp.getString(cardNumAuto.getText()
.toString(), ""));// 自动输入密码
}
});
// 登陆
logBT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cardNumStr = cardNumAuto.getText().toString();
passwordStr = passwordET.getText().toString();
if (!((cardNumStr.equals("test")) && (passwordStr
.equals("test")))) {
Toast.makeText(RemeberPwdActivity.this, "密码 误,请重新输入",
Toast.LENGTH_SHORT).show();
} else {
if (savePasswordCB.isChecked()) {// 登陆成功才保存密码
sp.edit().putString(cardNumStr, passwordStr).commit();
}
Toast.makeText(RemeberPwdActivity.this, "登陆成功,正在获取用户数据……",
Toast.LENGTH_SHORT).show();
// 跳转到另一个Activity
// do something
}
}
});
}
}
activity_remeber_pwd.xml
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/ic_launcher" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="简单登陆DEMO"
android:textSize="25px" />
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
android:layout_width="250dip"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:id="@+id/tv_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="用 户 名:"
android:textSize="15px" />
android:id="@+id/cardNumAuto"
android:textColor="#000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="用户密码:"
android:textSize="15px" />
android:id="@+id/passwordET"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:id="@+id/savePasswordCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="记住密码" >
android:id="@+id/logBT"
android:layout_width="100px"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:text="登录" >
android 登录保存密码,android 如何实现登陆界面的记住密码功能相关推荐
- android开发实例之minitwitter登录界面+代码,登录界面_记住密码
实现登录界面的记住密码功能 实验目的 1.掌握SharedPreferences类,这个类可以实现简单的存储,主要用于保存窗口状态 实验效果 主要代码 LoginActivity package co ...
- android模仿qq登录界面,初识Android二之小试牛刀模仿实现qq登陆界面
初识Android二之小试牛刀模仿实现qq登陆界面.俗话说得好,老师踢开门,修行在自己.勉勉强强学完生命周期,然后悠悠闲闲听了两节课后,老师就布置了一个登陆界面的实现,于是,磕磕绊绊的修行之路开始了. ...
- Android studio登录界面之记住密码
登录界面之记住密码 文章目录 登录界面之记住密码 文件存储的方式: 记住密码 存储数据 读取数据 完整代码 登录界面的博客: https://blog.csdn.net/genijmni/articl ...
- 登录界面的记住密码和密码的隐藏、显示
登录界面的记住密码功能 先上布局代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android& ...
- Android:登录保存回显用户信息或配置文件(sharedpreferences)
登录保存回显用户信息或配置文件(sharedpreferences) 目录 登录保存回显用户信息或配置文件(sharedpreferences) 1.项目目录结构 二.类:MainActivity 三 ...
- android登录程序代码,android 应用软件注册与自动登录代码
琢磨了很久 实现系统第一次启动显示欢迎及快速注册界面,注册成功后下次运行实现自动登录. 系统启动后首先进入系统主界面,读取用户名和密码,如果为空则直接跳转到快速注册界面,否则系统正常运行. 快速注册界 ...
- android 登录注册动画,Android开发(14)——动画实战:炫酷登录
本节内容 1.第三方库实现虚化 2.添加输入框和按钮 3.按钮状态 4.键盘隐藏 5.监听焦点改变的事件 6.手臂旋转动画 7.手掌和手臂动画 Demo简介 1.做一个炫酷登录的界面. image.p ...
- android布局基础及范例:QQ登陆界面设计
使用android手机的用户想必都有android手机QQ客户端吧,我们是不是觉得QQ登陆界面非常漂亮美观而且具有亲和力?我们是不是也想作出像 QQ那样美观的界面?有的人肯定会问,做UI那不是美工人员 ...
- Android开发之使用SharedPreferences实现QQ登陆的选项框记忆功能(源代码分享)
本系列文章由@林泓成出品,转载请注明出处. 根据上篇博客讲的SharedPreferences的简单实现,我们来实现下QQ登陆的时候用户名自动显示以及勾选是否记忆用户名和隐身登陆的功能,通过实例来展现 ...
最新文章
- iOS安全之RSA加密/生成公钥、秘钥 pem文件
- CTFshow 文件上传 web162
- DNS DHCP 路由 FTP
- finalshell日志乱码问题_Tomcat乱码问题
- 计算机二级考试C++考试大纲
- 最优化学习笔记(十四)——共轭梯度法
- 数学教材里的神秘数表在国外红出圈,网友:引人入胜、猜不到结局
- java.math.BigDecimal记录
- cannot load such file -- readline
- Wannafly挑战赛19:C. 多彩的树(状压+容斥)
- # C# 如何调用动态连接库?
- java resource文件_利用java如何实现读取resource目录下文件
- 扇入Fan-in和扇出Fan-out
- 电机控制器培训资料-《如何快准狠的标定永磁同步电机》 品牌:车用电机控制器
- python中用什么函数读取字符串_Python(2)字符串的主要方法
- java找茬_一起来找茬(1)-开发写的神奇左连接
- 高精度地图中的中英文专业词汇对照
- 阿里云本机一键登录集成
- 重新打开Word后公式中斜体变正体
- 率先布局“专精特新”,用友U9 cloud释放行业化专业服务红利
热门文章
- 11.SpringCloud
- 【幻灯片制作软件】Focusky教程 | 设置幻灯片播放时间间隔
- mvn package、mvn install和mvn deploy区别
- 奔图3305_奔图打印机耗材型号对照表
- 【机器学习与深度学习理论要点】10.什么是置信概率、什么是交叉验证、解决类别不均衡问题?
- mysql 繁体_mysql 插入繁体字报错?报错-问答-阿里云开发者社区-阿里云
- vr技术在计算机导论,清华大学出版社-图书详情-《虚拟现实与增强现实技术概论》...
- 远程对linux服务器安装theano+lasagne GPU配置
- 大咖说·云教育科技|教育数字化变革的实践探索之路
- STM32CubeMX新建Project、下载库