android中实现记住密码功能

本文介绍了如何在Android应用中使用SharedPreferences实现记住密码的功能。当用户登录时,如果选择了记住密码,程序将自动填充上次正确的用户名和密码。示例代码展示了在activity_main.xml布局文件中添加CheckBox控件,并在用户登录时保存和读取用户名与密码。
摘要由CSDN通过智能技术生成

运行效果图

11

实例程序讲解

在打开登陆界面时,程序会自动填写上次您输入正确的用户名和密码。小编本次为大家提供的是用SharePreferences对象来实现此功能的。

activity_main.xml

<span style="font-size:18px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/loginbg"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

  <include layout="@layout/login_top"/> 
  <include layout="@layout/login_bottom"/>"

</LinearLayout></span>
<strong>login_bottom.xml</strong>
<?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="wrap_content" >


    <TextView
        android:id="@+id/tvRegist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="18dp"
        android:text="@string/tvRegister"
        android:autoLink="all"
        android:textColorLink="#FF0066CC" />


    <ImageView
        android:id
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值