`

记住密码跟自动登录的设置

 
阅读更多

自动登录跟记住密码

 

 

首先定义一个登陆页面的ActivityLoginActivity

 

写道
package cn.hwttnet.com.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

public class LoginActivity extends Activity {
private EditText username, pass, url;
CheckBox remberPass, autoLogin;
Button login;
SharedPreferences sp;
Editor ed;
ImageButton ins;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
username = (EditText) findViewById(R.id.et_username);
pass = (EditText) findViewById(R.id.et_password);
url = (EditText) findViewById(R.id.et_url);
remberPass = (CheckBox) findViewById(R.id.remeber);
autoLogin = (CheckBox) findViewById(R.id.autoLogin);
login = (Button) findViewById(R.id.login);
ins = (ImageButton) findViewById(R.id.shuoming);
ins.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent3 = new Intent(LoginActivity.this,
InstrutionActivity.class);
startActivity(intent3);
}
});
sp = getSharedPreferences("users", MODE_WORLD_READABLE);
ed = sp.edit();
// 从SharedPreferences里边取出 记住密码的状态
if (sp.getBoolean("ISCHECK", false)) {
// 将记住密码设置为被点击状态
remberPass.setChecked(true);
// 然后将值赋值给EditText
username.setText(sp.getString("oa_name", ""));
pass.setText(sp.getString("oa_pass", ""));
url.setText(sp.getString("oa_url", ""));
// 获取自动登录按钮的状态
if (sp.getBoolean("AUTO_ISCHECK", false)) {
// 设置自动登录被点击 然后实现跳转
autoLogin.setChecked(true);
Intent intent1 = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent1);
}
}
login.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LoginMain();
}
});
// 将点击的checkBOx存入到users中
remberPass.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Boolean isChecked1 = remberPass.isChecked();
ed.putBoolean("ISCHECK", isChecked1);
ed.commit();
}
});
// 设置自动登录默认为不点击
Boolean value1 = sp.getBoolean("AUTO_ISCHECK", false);
autoLogin.setChecked(value1);
autoLogin.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Boolean isChecked2 = autoLogin.isChecked();
ed.putBoolean("AUTO_ISCHECK", isChecked2);
ed.commit();
}
});
// 如果记住密码跟自动登录都被选中就选择登录跳转
if (remberPass.isChecked() && autoLogin.isChecked()) {
LoginMain();
}
}

protected void LoginMain() {
// TODO Auto-generated method stub
// 将信息存入到users里面
ed.putString("oa_name", username.getText().toString());
ed.putString("oa_pass", pass.getText().toString());
ed.putString("oa_url", url.getText().toString());
ed.commit();
if (TextUtils.isEmpty(username.getText().toString())) {
Toast.makeText(this, "请输入用户名", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(pass.getText().toString())) {
Toast.makeText(this, "请输入密码", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(url.getText().toString())) {
Toast.makeText(this, "请输入连接地址", Toast.LENGTH_LONG).show();
return;
}

Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);

}
}

 定义一个登录界面的XML  login.xml

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

    <LinearLayout
        android:id="@+id/linearlayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/shuoming"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="250dip"
            android:layout_marginTop="40dip"
            android:src="@drawable/shuoming" />

        <ImageView
            android:id="@+id/image_logo"
            android:layout_width="250dip"
            android:layout_height="150dip"
            android:paddingLeft="8dip"
            android:paddingRight="8dip"
            android:src="@drawable/logo" />

        <TableLayout
            android:id="@+id/table01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:collapseColumns="4"
            android:stretchColumns="1" >

            <TableRow
                android:id="@+id/tableow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:paddingLeft="10dip"
                    android:textColor="#000000"
                    android:id="@+id/tv_username"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="用户名" />

                <EditText
                    android:id="@+id/et_username"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>

            <TableRow
                android:id="@+id/tableow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                      android:paddingLeft="10dip"
                    android:textColor="#000000"
                    android:id="@+id/tv_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="密码" />

                <EditText
                    android:id="@+id/et_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>

            <TableRow
                android:textColor="#000000"
                android:id="@+id/tableow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                      android:paddingLeft="10dip"
                     android:textColor="#000000"
                    android:id="@+id/tv_url"
                    android:layout_height="wrap_content"
                    android:text="地址" />

                <EditText
                    android:id="@+id/et_url"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </TableRow>
        </TableLayout>

        <LinearLayout
            android:id="@+id/tableLayout2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TableRow
                android:id="@+id/tableow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <CheckBox
                    android:textColor="#000000"
                    android:id="@+id/remeber"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="40dip"
                    android:text="记住密码" />

                <CheckBox
                    android:textColor="#000000"
                    android:id="@+id/autoLogin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="自动登录" />
            </TableRow>
        </LinearLayout>
    </LinearLayout>

    <Button
        android:id="@+id/login"
        android:layout_width="180dip"
        android:layout_height="wrap_content"
         android:layout_marginLeft="80dip"
        android:text="登录" />

</LinearLayout>

 

以上就实现了登录得记住密码,跟自动登录的实现

分享到:
评论

相关推荐

    制定CA6140车床拨叉的加工工艺,设计钻φ5孔的钻床夹具设计.rar

    制定CA6140车床拨叉的加工工艺,设计钻φ5孔的钻床夹具设计.rar

    128 基于STM32的儿童误锁车内远程报警系统【QT上位机源码】.zip

    这是 《128 基于STM32的儿童误锁车内远程报警系统【QT上位机源码】》 项目的Qt上位机上位机源码包。 这是一个Qt工程,采用QT5.12.6版本开发的源码。支持生成Windows系统运行程序。也支持生成Android手机APP。 对应项目的博客链接:https://blog.csdn.net/xiaolong1126626497/article/details/132015856 注意 注意 注意!!!: 如果不需要修改上位机源码,就不用下载本资源 (本项目的STM32源码包里就包含了上位机APP安装包,可以直接使用),在设计文档里也写了上位机的核心代码。 如果想学习本项目的上位机开发,学习上位机的源码,修改源。那么可以下载。 最好自己具备一定的Qt开发基础。

    水泥粉磨生产工艺流程图.zip

    水泥粉磨生产工艺流程图.zip

    ParagonHFS+forWin v14.0.24 x64.rar

    WINDOWS系统读取苹果分区的利器,支持HFS+及APFS分区。

    基于Ryu 控制器和 Mininet 实现软件定义网络(SDN)负载均衡解决方案,用于网络模拟.zip

    基于Ryu 控制器和 Mininet 实现软件定义网络(SDN)负载均衡解决方案,用于网络模拟.zip

    20250415API翻譯

    20250415API翻譯

    Git知识学习(尚硅谷)

    Git知识学习(尚硅谷)

    手机充电器的模具设计.zip

    手机充电器的模具设计.zip

    原神弹琴脚本,让风告诉你,只需要pynput库即可使用

    python

    基于SpringBoot的体育商品推荐系统(源码+数据库+万字文档+ppt)535

    基于SpringBoot的体育商品推荐系统,系统包含两种角色:管理员、用户主要功能如下。 【用户功能】 1. **首页:** 浏览体育商品推荐系统的主要信息。 2. **商品信息:** 查看系统推荐的体育商品。 3. **交流论坛:** 参与用户间的体育商品讨论和交流。 4. **公告资讯:** 查看系统发布的重要通知和体育商品资讯。 5. **留言板:** 发表个人意见和留言,参与系统互动。 6. **购物车:** 查看已选购的体育商品,进行结算和下单。 7. **个人中心:** 管理个人信息,查看订单历史和进行相关操作。 【管理员功能】 1. **首页:** 查看体育商品推荐系统。 2. **个人中心:** 修改密码、管理个人信息。 3. **用户管理:** 审核和管理注册用户的信息。 4. **商品分类管理:** 管理体育商品的分类信息。 5. **商品信息管理:** 监管和管理体育商品的信息。 6. **交流论坛:** 管理用户间的讨论和交流,包括删除不当内容。 7. **留言板:** 管理用户的留言,进行适当的处理。 8. **系统管理:** - **轮播图管理:** 管理系统首页的轮播图,包括添加、编辑和删除。 - **关于我们:** 编辑和更新关于体育商品推荐系统的介绍。 - **公告资讯:** 发布、编辑和删除系统的通知和公告。 - **系统简介:** 提供体育商品推荐系统的简要介绍。 9. **订单管理:** - **已退款订单:** 查看和管理已退款的订单信息。 - **未支付订单:** 查看和管理未支付的订单信息。 - **已发货订单:** 查看和管理已发货但未完成的订单信息。 - **已支付订单:** 查看和管理已支付但未完成的订单信息。 - **已完成订单:** 查看和管理已完成的订单信

    ### 【物联网操作系统】LiteOS从入门到实战:开发环境搭建、内核解析及网络编程详解、LiteOS简介

    内容概要:本文详细介绍了LiteOS这一轻量级物联网操作系统,涵盖其特点、应用场景、开发环境搭建、内核机制、实战演练及进阶学习。LiteOS由华为开发,专为资源受限设备设计,具备轻量级、高效性、安全性和开放性等特点,适用于智能家居、工业自动化、智能穿戴和智能城市建设等领域。文章逐步讲解了Windows和Linux系统下搭建LiteOS开发环境的具体步骤,包括安装交叉编译器、HiSpark Studio、配置Python环境、下载并配置LiteOS SDK等。深入探讨了LiteOS内核的任务管理和内存管理机制,并通过Hello World程序展示了创建任务、编写代码、编译和烧录的完整流程。最后,介绍了SAL及socket编程,提供了丰富的学习资源,包括官方文档、技术论坛和开源代码库。 适合人群:具备一定编程基础,尤其是对物联网开发感兴趣的开发者,以及希望深入了解嵌入式操作系统原理的技术人员。 使用场景及目标:①学习如何在资源受限的设备上开发高效稳定的应用程序;②掌握LiteOS的任务管理、内存管理等核心机制;③通过实战演练和进阶学习,提高物联网设备的网络通信能力,如使用SAL及socket编程实现设备与服务器之间的TCP通信。 其他说明:本文不仅提供了理论知识,还结合具体代码示例和实际操作步骤,帮助读者更好地理解和应用LiteOS。物联网技术正处于快速发展阶段,掌握LiteOS开发技能将为开发者在智能家居、工业自动化、智能穿戴等领域提供强大的竞争力。

    Android14请求存储权限适配demo源码

    Android开发14版本请求存储权限,它有部分允许权限,有一点难度。

    在vs集成开发环境中,使用C/C++开发的游戏:球球大作战(注意要使用EasyX库)

    在vs集成开发环境中,使用C/C++开发的游戏:球球大作战(注意要使用EasyX库)

    【露天矿山边坡安全监测】基于技术规范的金属非金属露天矿山边坡安全监测系统设计与实施:变形、应力、爆破振动及水文气象监测方法和要求

    内容概要:本文档为《露天矿山边坡安全监测技术规范》,旨在规定金属非金属露天矿山采场边坡安全监测的原则、内容、方法和技术要求,涵盖变形监测、采动应力监测、爆破振动监测、降雨和地下水监测、视频监控、在线监测系统等方面。文档详细介绍了监测系统的安装、维护和监测资料的整理分析等管理要求。通过定义边坡分类、安全监测分级、监测要求和具体监测方法,确保露天矿山边坡的安全性和稳定性。 适用人群:适用于从事露天矿山边坡安全监测的设计、施工、管理和研究人员,以及矿山企业的安全管理人员。 使用场景及目标:①用于指导露天矿山边坡的安全监测工作,确保监测系统的设计、安装、调试和运行符合标准;②通过对边坡变形、应力、爆破振动、水文气象等进行监测,预防和控制边坡失稳事故的发生;③利用在线监测系统和数据分析,实现对边坡安全状况的实时监控和预警。 其他说明:本文档不适用于与煤共生、伴生的金属非金属露天矿山采场边坡。文档提供了详细的监测方法和要求,强调了监测系统的兼容性、可扩展性和数据的安全存储。此外,还特别强调了定期巡查和信息反馈机制的重要性,以确保监测系统的有效运行和及时响应异常情况。

    acacia_door_bottom.png

    acacia_door_bottom

    Android开发不用存储权限进行拍照demo源码

    Android开发不用存储权限进行拍照,得到拍照后的图片效果。有一点难度,关键是存储路径的定义。

    27910240_g.zip

    27910240_g.zip

    Android开发红包动画效果demo源码

    Android开发红包动画效果,红包在那左晃右晃,吸引你点击。

    一些demo使用ElmentPlus的一些demo

    资源demo

    black_concrete.png

    black_concrete

Global site tag (gtag.js) - Google Analytics