Android实战简易教程-第六十六枪(结合SharedPreferenced实现自动登录功能)

本文介绍如何利用Android的SharedPreferenced来实现应用的自动登录功能,通过一个实例展示了从登录界面到登录成功的流程,并提到了退出应用后的自动登录测试。此外,还建议可以扩展实现登出操作来增强用户体验。
摘要由CSDN通过智能技术生成

我们使用的一般应用都有记住密码、自动登录功能,这样不用用户每次都要点击登录按钮,提升用户体验,下面我们通过一个实例研究一下如何通过android的sharedpreferenced实现自动登录功能。本实例有三个界面-登录界面,跳转界面,登录成功界面。

1.登录界面:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/logo_bg"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/img_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:background="@drawable/quit" />

        <TextView
            android:id="@+id/tv_zh"
            android:layout_width="wrap_content"
            android:layout_height="35dip"
            android:layout_marginLeft="12dip"
            android:layout_marginTop="10dip"
            android:gravity="bottom"
            android:text="帐号:"
            android:textColor="#000000"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_zh"
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:layout_below="@id/tv_zh"
            android:layout_marginLeft="12dip"
            android:layout_marginRight="10dip" />

        <TextView
            android:id="@+id/tv_mima"
            android:layout_width="wrap_content"
            android:layout_height="35dip"
            android:layout_below="@id/et_zh"
            android:layout_marginLeft="12dip"
            android:layout_marginTop="10dip"
            android:gravity="bottom"
            android:text="密码:"
            android:textColor="#000000"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/et_mima"
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:layout_
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值