存储登录密码及账号
来源:互联网 发布:济宁网络问政平台登录 编辑:程序博客网 时间:2024/04/26 08:47
掌握 SharedPreferences 的使用
1.将所用到的图片素材粘贴到drawable,将登录页面进行设计,代码如下;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
android:background="@drawable/logintop_roundbg">
<EditText android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/edit_text"
android:drawableLeft="@drawable/icon_user"
android:drawablePadding="10dp"android:ems="10"
android:hint="@string/etName">
<requestFocus />
</EditText>
<EditText android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/etName"
android:background="@android:drawable/edit_text"
android:drawableLeft="@drawable/icon_pass"
android:drawablePadding="10dp"
android:ems="10"android:hint="@string/ctPass">
<requestFocus />
</EditText>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/etPassword">
<CheckBox android:text="记住密码"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/cbIsRememberPass"
android:textSize="20sp"android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:background="@drawable/btn_seclet"
android:onClick="login"android:text="登录" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<TextView android:text="Welcome you"
</RelativeLayout>
在LoginActivity中配置
“`package com.example.administrator.case_login;
import Android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.content.SharedPreferencesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
private EditText etName;
private EditText etPassword;
private CheckBox cbIsRememberPass;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initViews(); sharedPreferences= getSharedPreferences("rememberpassword",Context.MODE_PRIVATE); boolean isRemember=sharedPreferences.getBoolean("rememberpassword",false); if(isRemember){ String name=sharedPreferences.getString("name",""); String password =sharedPreferences.getString("password",""); etName.setText(name); etPassword.setText(password); cbIsRememberPass.setChecked(true); }}private void initViews(){ etName=(EditText)findViewById(R.id.etName); etPassword=(EditText) findViewById(R.id.etPassword); cbIsRememberPass=(CheckBox)findViewById(R.id.cbIsRememberPass);}public void login(View view){ String name=etName.getText().toString(); String password=etPassword.getText().toString(); if("admin".equals(name)&&"123456".equals(password)){ SharedPreferences.Editor editor=sharedPreferences.edit(); if(cbIsRememberPass.isChecked()){ editor.putBoolean("rememberpassword",true); editor.putString("name",name); editor.putString("password",password); }else{ editor.clear(); } editor.commit(); Intent intent=new Intent(this,MainActivity.class); startActivity(intent); finish(); }else{ Toast.makeText(this,"账号或密码有误", Toast.LENGTH_LONG).show(); }}
}
“
当用户选中了记住密码复选框,并成功登录一次之后,这个时候如果再重新启动登录界面,之前输入的用户名和密码就会显示在文本框中。
- 存储登录密码及账号
- 更改登录账号的类型及密码
- NSUserDefaults轻量级存储数据(登录的账号密码)
- 登录窗体验证账号密码
- 实验任务7 实现登录界面的账号和密码的存储功能
- 利用h5的本地存储实现登录页面里的记住账号和密码功能
- QTP:Flight账号及密码
- 使用BCrypt算法加密存储登录密码用法及好处
- PL/SQL 记录登录账号密码
- PL/SQL 记录登录账号密码
- 设置登录窗体并验证账号密码
- 重新设置oracle登录账号和密码
- 简易QQ登录实现账号密码保存
- android登录之后保存账号密码
- 账号密码登录(Account password authentication)
- 服务器客户端模拟账号密码登录
- SSH登录验证用户账号密码实现
- 账号密码登录与用户交互
- marquee实现文字滚动效果
- Docker实战小记
- [深度学习论文笔记][ECCV 16]Embedding Deep Metric for Person Re-identication A Study Against Large Variations
- 项目搭建中的遇到的问题
- opencv 鼠标选取图像感兴趣区域
- 存储登录密码及账号
- 爬虫学习日记二:相关图片的爬取(附代码)
- 面向对象高级( 随手记-4)
- 从np.random.normal()到正态分布的拟合
- 矩阵计算一些重要的结论及其证明
- Zoj 3956 Course Selection System【01背包】
- Telephone--短信发送/接收流程
- JZOJ1275.【USACO题库】2.4.5 Fractions to Decimals分数化小数
- c++第四次作业报告 项目2.3.4