位置: 编程技术 - 正文

安卓登陆框记住密码和自动登录的实现(登陆界面android)

编辑:rootadmin

推荐整理分享安卓登陆框记住密码和自动登录的实现(登陆界面android),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:安卓登陆框记住密码忘了,安卓登录界面布局设计,安卓登录界面布局设计,安卓登陆框记住密码忘了,安卓用户登陆界面,安卓登陆框记住密码忘了,安卓登陆框记住密码忘了,安卓登陆框记住密码忘了,内容如对您有帮助,希望把文章链接给更多的朋友!

效果图:

1.在AndroidMainfest文件中注册activity;运行了下还是不行

2.在MainActivity.java文件中的Intent intent = new Intent();intent.setClass(MainActivity.this, SuccessActivity1.class);这两句后边加这一句 startActivity(intent);3.替换文件,改包名:package com.example.minitwittersimulate;4.创建home.xml文件5.创建LoginActivity.java文件6.将LoginActivity.java中的MainActivity改为LoginAvtivity 此时运行显示错误,因为没有在AndroidMainfest.xml文件中注册LoginActivity

7.在AndroidMainfest中注册Activity。

8.运行成功!

LoginActivity.java

package com.example.minitwittersimulate;

import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.Window;import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;

public class LoginActivity extends Activity { private EditText etUsername; private EditText etPassword; private CheckBox cbRememberPass; private CheckBox autologin1; private Button btnLogin ; private SharedPreferences sp; private String userNameValue,passwordValue;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); // 初始化用户名、密码、记住密码、自动登录、登录按钮 etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); cbRememberPass = (CheckBox) findViewById(R.id.cbRememberPass); autologin1 = (CheckBox) findViewById(R.id.autologin1); btnLogin = (Button) findViewById(R.id.btnLogin);

sp = getSharedPreferences("userInfo", 0); String name=sp.getString("USER_NAME", ""); String pass =sp.getString("PASSWORD", "");

boolean choseRemember =sp.getBoolean("cbRememberPass", false); boolean choseAutoLogin =sp.getBoolean("autologin1", false); //如果上次选了记住密码,那进入登录页面也自动勾选记住密码,并填上用户名和密码 if(choseRemember){ etUsername.setText(name); etPassword.setText(pass); cbRememberPass.setChecked(true); } //如果上次登录选了自动登录,那进入登录页面也自动勾选自动登录 if(choseAutoLogin){ autologin1.setChecked(true); } btnLogin.setOnClickListener(new OnClickListener() { // 默认可登录帐号xs,密码 @Override public void onClick(View arg0) { userNameValue = etUsername.getText().toString(); passwordValue = etPassword.getText().toString(); SharedPreferences.Editor editor =sp.edit(); // TODO Auto-generated method stub if (userNameValue.equals("wx") && passwordValue.equals("")) { Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show(); //保存用户名和密码 editor.putString("USER_NAME", userNameValue); editor.putString("PASSWORD", passwordValue); //是否记住密码 if(cbRememberPass.isChecked()){ editor.putBoolean("cbRememberPass", true); }else{ editor.putBoolean("cbRememberPass", false); }

//是否自动登录 if(autologin1.isChecked()){ editor.putBoolean("autologin1", true); }else{ editor.putBoolean("autologin1", false); } editor.commit(); //跳转 //Intent intent =new Intent(MainActivity.this,SuccessActivity1.class); //startActivity(intent); Intent intent = new Intent(); intent.setClass(LoginActivity.this, SuccessActivity1.class); startActivity(intent); } else { Toast.makeText(LoginActivity.this, "用户名或密码错误,请重新登录!", Toast.LENGTH_SHORT).show(); }

}

});

}

@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }

}

MainActivity.java

package com.example.minitwittersimulate;

import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.view.View;import android.widget.TextView;import android.widget.Toast;

public class MainActivity extends Activity { private SharedPreferences sp; private TextView talk; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); talk =(TextView) findViewById(R.id.talk); sp=getSharedPreferences("userInfo", 0); String name =sp.getString("USER_NAME", ""); boolean choseAutoLogin =sp.getBoolean("autologin1", false); if(choseAutoLogin){ talk.setVisibility(0); talk.setText(name&#;"自动登录成功"); }

} //跳转到登录页面 public void go(View v){ Intent intent =new Intent(this, LoginActivity.class); startActivity(intent); } //点击退出销毁登录记录 public void out(View v){ SharedPreferences spout =getSharedPreferences("userInfo", 0); SharedPreferences.Editor ed =spout.edit(); ed.clear(); ed.commit(); Toast.makeText(this, "销毁记录", Toast.LENGTH_SHORT).show(); }}

SuccessActiviy.java

package com.example.minitwittersimulate;

import android.app.Activity;import android.os.Bundle;import android.view.View;

安卓登陆框记住密码和自动登录的实现(登陆界面android)

public class SuccessActivity1 extends Activity {

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sucess); } public void outactivity(View v){ System.exit(0); }}

activity_main.xml

<LinearLayout xmlns:android=" xmlns: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>

home.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"

android:orientation="vertical" >

<TextView android:id="@&#;id/talk" android:layout_width="match_parent" android:layout_height="dp" android:text="文本" android:gravity="center" android:visibility="gone" /> <Button android:id="@&#;id/gologin" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:onClick="go" /> <Button android:id="@&#;id/out" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="注销" android:onClick="out" /></LinearLayout>

login_bottom.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns: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="dp" android:layout_marginTop="dp" android:text="@string/tvRegister" android:autoLink="all" android:textColorLink="#FFCC" />

<ImageView android:id="@&#;id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="dp" android:src="@drawable/icon" />

<ImageView android:id="@&#;id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@&#;id/imageView2" android:src="@drawable/jiqimao1" />

</RelativeLayout>

login_top.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/btnbg_roundcorner" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" >

<TextView android:id="@&#;id/tvUsername" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/tvName" android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText android:id="@&#;id/etUsername" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@&#;id/tvUsername" android:layout_below="@&#;id/tvUsername" android:background="@android:drawable/edit_text" android:ems="" >

<requestFocus /> </EditText>

<TextView android:id="@&#;id/tvPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@&#;id/etUsername" android:layout_below="@&#;id/etUsername" android:text="@string/tvPassword" android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText android:id="@&#;id/etPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@&#;id/tvPassword" android:layout_below="@&#;id/tvPassword" android:layout_marginTop="dp" android:background="@android:drawable/edit_text" android:ems="" android:inputType="textPassword" />

<Button android:id="@&#;id/btnLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@&#;id/etPassword" android:layout_below="@&#;id/etPassword" android:layout_marginTop="dp" android:background="#FFCAE1" android:text="@string/btnLogin" />

<CheckBox android:id="@&#;id/cbRememberPass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@&#;id/etPassword" android:layout_alignTop="@&#;id/btnLogin" android:text="记住密码" />

<CheckBox android:id="@&#;id/autologin1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@&#;id/cbRememberPass" android:layout_below="@&#;id/cbRememberPass" android:text="自动登录" />

</RelativeLayout>

success.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >

<TextView android:id="@&#;id/textView1" android:layout_width="match_parent" android:layout_height="dp" android:gravity="center" android:text="登录成功,重启程序才可以看到效果哦~" /> </LinearLayout>

Android API文档_AudioFormat 概述软件包类使用树已过时索引帮助JavaTM2PlatformStandardEd.6上一个类下一个类框架无框架所有类摘要:嵌套|字段|构造方法|方法详细信息:字段|构造方法|

R.java was modified manually! Reverting to generated version!项目显示红色感叹号 自己遇到的问题:找了很多网上的解决办法未果后,查看了BuildPath里。SVN多添加了一个jar引用导致出错,删除即可!

Activity重识 Activity在我们开发中就是一个界面的载体,各种各样的应用都是通过Activity加载显示的。一、单个Activity的生命周期在AndroidDeveloper文档中有个图片描述了A

标签: 登陆界面android

本文链接地址:https://www.jiuchutong.com/biancheng/386719.html 转载请保留说明!

上一篇:Android alertDialog 动态添加edittext无法弹出键盘解决方案

下一篇:Android API文档_AudioFormat(android sdk api文档)

  • 企业投资收益要开发票吗
  • 园林绿化公司范围
  • 新企业会计准则2021
  • 金蝶利润表没有数据怎么办
  • 结转存货跌价准备冲减主营业务成本
  • 营业税金及附加借贷方向
  • 临时设施费怎么结算
  • 收到员工归还借款属于现金流量表
  • 记账凭证账务处理程序步骤
  • 暂估的成本跨年了怎么冲销后要调整报表吗
  • 认缴制下实收资本印花税
  • 所得税汇算清缴时间期限
  • etc预付卡发票能不能报销
  • 电子钥匙的发票怎么开
  • 企业公司报税流程
  • 出纳收到汇票如何登记
  • 以前的员工怎么交社保
  • 收料单的会计分录怎么做
  • 如何以快捷方式打印文件
  • 鸿蒙系统怎么开发
  • 无法访问您可能没有权限使用资源
  • 母公司是否应替子公司承担违约责任
  • 购买银行承兑汇票是否违法
  • window11正式版什么时候出来
  • PHP:highlight_string()的用法_misc函数
  • 苹果官网
  • vue打包vendor文件过大
  • 梅德威海滩棕榈树间散步的冲浪者,印尼巴厘岛 (© helivideo/GettyImages)
  • 混合成本的分解方法很多,通常有
  • 增值税留抵抵欠流程
  • 报废机器设备如何缴纳增值税
  • 财务章和公章下面数字一样吗
  • 支付版权费用账号是什么
  • 金蝶k3现金流量表编制如何生成数据
  • 发票打印错误如何修改
  • 增值税主要内容
  • 定期存款一次性可以存多少钱
  • 织梦怎么样
  • Linux下MySQL卸载和安装图文教程
  • mongodb用户权限
  • 以前年度盈余调整对应科目
  • sqlserver2008密码要求
  • 增值税发票查询全国统一发票查询平台
  • 小规模在税务局开专票需要什么材料
  • 建筑公司工程款税率
  • 消费税会计分录处理
  • 实际发的工资跟个人所得税不一样怎么办
  • 车辆处置如何缴纳企业所得税
  • 月末应交增值税借方余额期末该怎么处理
  • 企业研发费用包括工资支出吗
  • 资产负债表中的固定资产是原值还是净值
  • 2020年工伤赔偿标准表
  • 财务预算编制方法包括
  • 目前用到的两个字符
  • 在Linux环境下mysql的root密码忘记解决方法(三种)
  • 电脑出现蓝屏后黑屏怎么办
  • centos7修改文件内容
  • win10周年更新版是什么意思
  • make:arm-linux- conmand not found错误处理探讨
  • win7还原按钮
  • win8 metro界面
  • win7无法安装怎么办
  • win8系统怎么设置桌面
  • windows媒体中心关不掉
  • linuxat命令的用法
  • 如何在linux安装软件
  • css命名大全
  • 京东试用js脚本
  • shell的变量分为哪三种
  • shell常用命令及示例
  • python下载方法
  • jquery轮播代码
  • python多线程技术
  • 税控盘离线开票时间怎么查
  • 一般纳税人开红字发票怎么报税
  • 高端护肤品品牌排行榜
  • 年税怎么扣
  • 02112366电子税务局
  • 重庆外经证网上报验流程及时间
  • 上海市网上税务局如何登录
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设