广告
返回顶部
首页 > 资讯 > 移动开发 >Android实现记住密码小功能
  • 597
分享到

Android实现记住密码小功能

2024-04-02 19:04:59 597人浏览 泡泡鱼
摘要

本文实例为大家分享了Android实现记住密码小功能的具体代码,供大家参考,具体内容如下 以下有三个点 第一点是记住密码, 第二点是点击隐藏点击显示, 第三点是登录存储。 XML布

本文实例为大家分享了Android实现记住密码小功能的具体代码,供大家参考,具体内容如下

以下有三个点 第一点是记住密码, 第二点是点击隐藏点击显示, 第三点是登录存储。

XML布局


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".v.MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textSize="20sp"
        android:textColor="#FFEB3B"
        android:gravity="center"
        android:padding="10dp"
        android:background="#8BC34A"
        >
    </TextView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="50dp"
        >

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="邮箱:"
          android:textColor="#03A9F4"
          android:textSize="15sp"
          android:textStyle="italic"
          android:layout_marginLeft="30dp"
          android:padding="10dp"
          >
      </TextView>

      <EditText
          android:id="@+id/youxiang"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="请输入邮箱"
          android:paddingLeft="10dp"
          android:textColorHint="#FF5722"
          android:textStyle="italic"
          android:layout_marginRight="40dp"
          >
      </EditText>


    </LinearLayout>


  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:layout_marginTop="10dp"
      >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密码:"
        android:textColor="#03A9F4"
        android:textSize="15sp"
        android:textStyle="italic"
        android:layout_marginLeft="30dp"
        android:padding="10dp"
        >
    </TextView>

    <EditText
        android:id="@+id/mima"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:hint="请输入密码"
        android:paddingLeft="10dp"
        android:textColorHint="#FF5722"
        android:textStyle="italic"
        >
    </EditText>

    <ImageView
        android:id="@+id/can"
        android:layout_width="20dp"
        android:layout_height="match_parent"
        android:src="@mipmap/login_icon_hide_passWord_n"
        android:layout_marginRight="20dp"
        >
    </ImageView>
  </LinearLayout>


  <CheckBox
      android:id="@+id/ji"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="记住密码"
      android:textColor="#FF5722"
      android:layout_marginLeft="40dp"
      android:layout_marginTop="15dp"
      >
  </CheckBox>


  <Button
      android:id="@+id/deng"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="登录"
      android:textColor="#FF5722"
      android:background="#03A9F4"
      android:textStyle="bold"
      android:textSize="15sp"
      android:layout_margin="30dp"
      >
  </Button>
</LinearLayout>

Java代码


package com.wd.health.v;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.method.HideReturnsTransfORMationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.wd.health.R;
import com.wd.health.base.BaseActivity;
import com.wd.health.bean.LoginBean;
import com.wd.health.contract.ILoginContract;
import com.wd.health.net.RsaCoder;
import com.wd.health.p.LoginPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity<LoginPresenter> implements ILoginContract.ILoginView {

    @BindView(R.id.can)
    ImageView can;
    @BindView(R.id.ji)
    CheckBox ji;
    @BindView(R.id.deng)
    Button deng;
    @BindView(R.id.youxiang)
    EditText youxiang;
    @BindView(R.id.mima)
    EditText mima;
    boolean sb=true;
    private SharedPreferences user;
    private SharedPreferences.Editor edit;

    @Override
    protected int initView() {
        return R.layout.activity_main;
    }

    @Override
    protected LoginPresenter CreatPresenter() {
        return new LoginPresenter();
    }

    @Override
    protected void loadData() {
        ButterKnife.bind(this);
        //默认是隐藏
        mima.setTransformationMethod(PasswordTransformationMethod.getInstance());
        //点击小眼睛
        can.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (sb){
                    can.setImageResource(R.mipmap.login_icon_show_password);
                    mima.setTransformationMethod(HideReturnsTransformationMethod.getInstance());    //显示
                    sb=false;
                }else {
                    can.setImageResource(R.mipmap.login_icon_hide_password_n);
                    mima.setTransformationMethod(PasswordTransformationMethod.getInstance());   //隐藏
                    sb=true;
                }
            }
        });
        //记住密码
        user = getSharedPreferences("user", MODE_PRIVATE);
        boolean isRemenber = user.getBoolean("remember_password", false);
        if(isRemenber){
            youxiang.setText(user.getString("phone",""));
            mima.setText(user.getString("password",""));
            ji.setChecked(true);
        }

        //点击登录
        deng.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s1 = youxiang.getText().toString();      //获取输入框邮箱
                String s2 = mima.getText().toString();          //获取输入框密码
                String a="";        //存放加密的密码
                try {
                    a = RsaCoder.encryptByPublicKey(s2);        //加密后的密码
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (s1.equals("")){         //如果邮箱为空则吐司
                    Toast.makeText(MainActivity.this, "请输入邮箱", Toast.LENGTH_SHORT).show();
                }else if (s2.equals("")){   //如果密码为空则吐司
                    Toast.makeText(MainActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
                }else {
                    //这是MVP调用的P层
                    mPresenter.ShowDengPresenter(s1,a);     //s1是邮箱  a是加密的密码
                    //记住密码
                    edit = user.edit();
                    if(ji.isChecked()){
                        edit.putBoolean("remember_password",true);
                        edit.putString("phone",s1);        //没有加密的邮箱
                        edit.putString("password",s2);      //没有加密的密码
                    }else{
                        edit.clear();
                    }
                    edit.apply();
                }

            }
        });

    }

    @Override
    public void ShowDengView(LoginBean loginBean) {
        Toast.makeText(this, loginBean.getMessage(), Toast.LENGTH_SHORT).show();
        if (loginBean.getStatus().equals("0000")){
            user.edit().putString("userId",String.valueOf(loginBean.getResult().getUserId()))
                    .putString("sessionId",loginBean.getResult().getSessionId())
                    .putString("nickName",loginBean.getResult().getNickName())
                    .putString("userName",loginBean.getResult().getUserName())
                    .putString("jiGuangPwd",loginBean.getResult().getJiGuangPwd())
                    .putString("headPic",loginBean.getResult().getHeadPic())
                    .putString("sex",String.valueOf(loginBean.getResult().getSex()))
                    .putString("age",String.valueOf(loginBean.getResult().getAge()))
                    .putString("height",String.valueOf(loginBean.getResult().getHeight()))
                    .putString("weight",String.valueOf(loginBean.getResult().getWeight()))
                    .putString("email",String.valueOf(loginBean.getResult().getEmail()))
                    .putString("whetherBingWeChat",String.valueOf(loginBean.getResult().getWhetherBingWeChat()))
                    .putString("invitationCode",String.valueOf(loginBean.getResult().getInvitationCode()))
                    .putString("faceFlag",String.valueOf(loginBean.getResult().getFaceFlag()))
                    .commit();
            //成功后跳转到首页
            Intent intent = new Intent(MainActivity.this,HomeActivity.class);
            startActivity(intent);
            finish();
        }

    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Android实现记住密码小功能

本文链接: https://www.lsjlt.com/news/136482.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android实现记住密码小功能
    本文实例为大家分享了Android实现记住密码小功能的具体代码,供大家参考,具体内容如下 以下有三个点 第一点是记住密码, 第二点是点击隐藏点击显示, 第三点是登录存储。 XML布...
    99+
    2022-11-12
  • Android实现记住用户名和密码功能
    Android 实现记住用户名和密码的功能是通过SharedPreference 存储来实现的。创建一个复选按钮,通过按钮的否选取来进行事件处理。若按钮选中存储账号和密码的信息...
    99+
    2022-06-06
    用户名 Android
  • Android实现登陆界面的记住密码功能
    本文实例为大家分享了Android实现登陆界面记住密码功能的具体代码,供大家参考,具体内容如下 所需工具 一、复选框控件:CheckBox,二、SharedPreferences用于...
    99+
    2022-11-13
  • Android中怎么使用SQLite实现记住密码功能
    这期内容当中小编将会给大家带来有关Android中怎么使用SQLite实现记住密码功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。具体内容如下package com.example.alimj...
    99+
    2023-05-31
    android sqlite
  • Android如何实现登陆界面的记住密码功能
    这篇文章主要介绍“Android如何实现登陆界面的记住密码功能”,在日常操作中,相信很多人在Android如何实现登陆界面的记住密码功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Android如何实现登陆...
    99+
    2023-06-30
  • Android实现带有记住密码功能的登陆界面
    本文实例为大家分享了Android带有记住密码功能的登陆界面实现代码,供大家参考,具体内容如下 1、设计思路 主要采用SharedPreferences来保存用户数据,本Dem...
    99+
    2022-06-06
    登陆 界面 Android
  • Android中怎么实现登录记住多个密码功能
    这篇文章将为大家详细讲解有关Android中怎么实现登录记住多个密码功能,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。在popouWindow里面加上ListView,数据是把List以字符...
    99+
    2023-05-31
    android
  • Android中的密码记住功能怎么利用 sharedPreferences实现
    本篇文章给大家分享的是有关Android中的密码记住功能怎么利用 sharedPreferences实现,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。编写界面交互代码:pack...
    99+
    2023-05-31
    sharedpreferences android roi
  • 如何在Android应用中实现一个记住密码功能
    本篇文章给大家分享的是有关如何在Android应用中实现一个记住密码功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。一、打开之前完成的Case_login进行修改再编辑二、将...
    99+
    2023-05-31
    android roi
  • Vue如何实现记住账号密码功能
    这篇“Vue如何实现记住账号密码功能”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Vue如何实现记住账号密码功能”文章吧。实...
    99+
    2023-07-02
  • 微信小程序记住密码的功能简单几步实现
    目录实现思路实现源码实现思路 其实实现的核心思路非常简单,就是通过 wx.setStorageSync() 与 wx.getStorageSync() 方法在登录后将登录的信息进行存...
    99+
    2023-01-28
    微信小程序记住密码 小程序记住密码
  • LocalStorage如何实现记住用户和密码功能
    这篇文章主要介绍了LocalStorage如何实现记住用户和密码功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 随着HTML5...
    99+
    2022-10-19
  • JavaWeb 中Cookie实现记住密码的功能示例
    本文主要内容:•1、什么是Cookie•2、Cookie带来的好处•3、Cookie的主要方法 一、什么是Cookiecookie是一种WEB服务器通过浏览器在访问者的硬盘上存储信息的手段。Co...
    99+
    2023-05-31
    java web cookie
  • Android 使用SharedPreferrences储存密码登录界面记住密码功能
    Android存储方式有很多种,在这里所用的存储方式是SharedPreferrences, 其采用了Map数据结构来存储数据,以键值的方式存储,可以简单的读取与写入。所以比较...
    99+
    2022-06-06
    界面 Android
  • html5中如何使用localStorage实现记住密码功能
    这篇文章给大家分享的是有关html5中如何使用localStorage实现记住密码功能的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。HTML5 提供了两种在客户端存储数据的新方法...
    99+
    2022-10-19
  • Vue如何实现登录记住账号密码功能
    本篇内容主要讲解“Vue如何实现登录记住账号密码功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Vue如何实现登录记住账号密码功能”吧!实现思路用户登录时若勾选“记住我”功能选项,则将登录名和...
    99+
    2023-06-21
  • Android中使用SharedPreferences完成记住账号密码的功能
    效果图:记住密码后,再次登录就会出现账号密码,否则没有。分析:SharedPreferences可将数据存储到本地的配置文件中SharedPreferences会记录CheckBox的状态,如果CheckBox被选,则将配置文件中记录的账号...
    99+
    2023-05-30
    android sharedpreferences roi
  • Vue实现记住账号密码功能的操作过程
    目录实现思路:记住账号密码实现流程npm安装base64依赖实现思路:   用户登录时若勾选“记住我”功能选项,则将登录名和密码(加密后)存入本地缓存,下次登...
    99+
    2022-11-13
  • JS实现密码箱小程序帮你记住各种密码
    目录说在前面设计思路1、进入密码箱前加密2、密码箱数据加密3、密码数据增删改查4、密码分类展示功能实现1、手势图案锁组件2、数据AES加密解密2.1 引入CryptoJS2.2 封装...
    99+
    2022-11-13
  • Android实现登录界面记住密码的存储
    Android存储方式有很多种,在这里所用的存储方式是SharedPreferrences, 其采用了Map数据结构来存储数据,以键值的方式存储,可以简单的读取与写入。所以比较...
    99+
    2022-06-06
    界面 存储 Android
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作