利用android编写的可记住用户名和密码并能制动登陆的登陆界面。

MainActivity.java文件

public class MainActivity extends Activity {private EditText mEtUserName;             //账号private EditText mEtPassWord;             //密码private CheckBox mCbKeepPsd;              //是否保存密码复选框private Button mBtnLogin;                 //登录按钮  private CheckBox mCbKeeppsd1;             //是否自动登录按钮private SharedPreferences mSpSettings = null;private static final String PREFS_NAME = "NamePwd";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);findView();setListener();getData();}/*** 绑定控件*/private void findView() {// TODO Auto-generated method stubmEtUserName = (EditText) findViewById(R.id.etUsername);mEtPassWord = (EditText) findViewById(R.id.etPassword);mCbKeepPsd = (CheckBox) findViewById(R.id.cbKeepPsd);mBtnLogin = (Button) findViewById(R.id.btnLogin);mCbKeeppsd1 = (CheckBox) findViewById(R.id.cbKeeppsd1);}/*** 为控件添加事件*/private void setListener() {// TODO Auto-generated method stub//判断自动登录复选框是否选中if(mCbKeeppsd1.isChecked()){mSpSettings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);Editor edit = mSpSettings.edit();Intent intent = new Intent(MainActivity.this,SuccessActivity.class);startActivity(intent);}else{mBtnLogin.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {// TODO Auto-generated method stub//判断用户名和密码if("geng".equals(mEtUserName.getText().toString()) && "123456".equals(mEtPassWord.getText().toString())){//判断记住密码复选框是否选中if(mCbKeepPsd.isChecked()){mSpSettings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);Editor edit = mSpSettings.edit();edit.putBoolean("isKeep", true);edit.putString("username", mEtUserName.getText().toString());edit.putString("password", mEtPassWord.getText().toString());edit.commit();} else {mSpSettings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);Editor edit = mSpSettings.edit();edit.putBoolean("isKeep", false);edit.putString("username", "");edit.putString("password", "");edit.commit();}Intent intent = new Intent(MainActivity.this,SuccessActivity.class);startActivity(intent);} else {Toast.makeText(getApplicationContext(),"用户名或密码错误",Toast.LENGTH_SHORT).show();}}});}}protected void onResume(){super.onResume();getData();}private void getData() {// TODO Auto-generated method stubmSpSettings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);if(mSpSettings.getBoolean("isKeep", false)){mEtUserName.setText(mSpSettings.getString("username", ""));mEtPassWord.setText(mSpSettings.getString("password", ""));} else {mEtUserName.setText("");mEtPassWord.setText("");}}@Overridepublic 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;}}

SuccessActivity.Java

public class SuccessActivity extends Activity{protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.success_main);}}

activity_main.xml

<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>

login_bottom.xml

<?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" ><TextViewandroid: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" /><ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_marginBottom="24dp"android:src="@drawable/panda" /><ImageViewandroid:id="@+id/imageView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:layout_marginBottom="28dp"android:src="@drawable/icon" /></RelativeLayout>

login_top.xml

<?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"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" ><TextViewandroid: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" /><EditTextandroid: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="10" ><requestFocus /></EditText><TextViewandroid: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" /><EditTextandroid: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="16dp"android:background="@android:drawable/edit_text"android:ems="10"android:inputType="textPassword" /><Buttonandroid: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="20dp"android:background="#FF72CAE1"android:text="@string/btnLogin" /><CheckBoxandroid:id="@+id/cbKeeppsd1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignTop="@+id/btnLogin"android:layout_toRightOf="@+id/cbKeepPsd"android:text="自动登录" /><CheckBoxandroid:id="@+id/cbKeepPsd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/cbKeeppsd1"android:layout_alignBottom="@+id/cbKeeppsd1"android:layout_alignLeft="@+id/etPassword"android:text="记住密码" /></RelativeLayout>

success_main.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:orientation="vertical" ><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="登陆页面"android:textAppearance="?android:attr/textAppearanceLarge" /></LinearLayout>

Android 登陆界面相关推荐

  1. android登陆界面左右两种登陆布局,Android UI组件----用相对布局RelativeLayout做一个登陆界面...

    [声明] 欢迎转载,但请保留文章原始出处→_→ [正文] 两个小时的学习成果,对于我这种还没入门但渴望不断进步的初学者来说,是一种激励.通过自己一行一行的敲代码,实现了用相对布局做一个登陆界面的效果. ...

  2. Android登陆界面设计demo

    在网上在到一个登录界面感觉挺不错的,给大家分享一下~先看效果图: 这个Demo除了按钮.小猫和Logo是图片素材之外,其余的UI都是通过代码实现的. 一.背景 背景蓝色渐变,是通过一个xml文件来设置 ...

  3. android登陆界面ui设计,UI设计师必备技能:常用字体规范

    作为一个@王铎(MICU设计)带来的界面设计常用字体规范,大家看完果断收藏. 作者:王铎(MICU设计) 好长时间没发帖,净想过年了,过年哈,倒腾工作总结和年货是大事. 这几天有人问我说:" ...

  4. android 登陆界面动画,【Android开发】动画登录页面

    心得感悟 这个Demo对我还是比较有难度的,花了好久去理解.因为动画比较有趣,所以想自己改改样式,也有助于自己的理解.这是进入Android开发学习第六天了,每天的学习都是懂了很多,却还有很多不懂,还 ...

  5. android登陆界面设计方案,011android初级篇之android登录界面的设计

    设计目标 密码账户的输入 输入账户时,自动显示匹配账户 没有帐号,显示官网超链接 登录框的自动提示功能参考一下链接中的AutoCompleteTextView的使用 布局文件 android:orie ...

  6. c# 程序员学习android(2)登陆界面

    上次说的是引导界面本次我们说说登陆界面 android的登陆界面很多.我想做一个类似于qq的但是头像是圆形的这种,下面是样图 我想做成这样的,这里有两个技术难点,一个是这个圆形的图,一个是下面的用户名 ...

  7. Android学习之登陆界面设计(一)前后期准备以及相关配置

    Android学习之登陆界面设计(一)前后期准备以及相关配置 前言 成品 成品样式 成品特点 工具 系统配置 手机配置 Android Studio 3.6.3 SDK 图片来源 矢量图标库 Back ...

  8. Android学习之登陆界面设计(二)基本界面设计

    Android学习之登陆界面设计(二)基本界面设计 前提 绘图样式 - drawable bg_login_btn_submit.xml bg_login_panel_slide.xml bg_log ...

  9. Android仿QQ微信开场导航以及登陆界面

    相信大家对于微信等社交应用的UI界面已经都很熟悉了,该UI最值得借鉴的莫过于第一次使用的时候一些列产品介绍的图片,可以左右滑动浏览,最后进入应用,这一效果适用于多种项目中,相信今后开发应用一定会用得到 ...

最新文章

  1. R语言pacman包管理R编程语言需要的包实战:使用p_load函数安装和加载多个R包、使用p_unload函数卸载多个R包、使用p_update函数更新过期的R包
  2. NIX***检测方法
  3. ORA-01102: cannot mount database in EXCLUSIVE mode
  4. 动态可订制属性的 PropertyGrid(转载)
  5. mysql cross apply_SQL Server CROSS APPLY和OUTER APPLY的应用详解
  6. 广东全国计算机二级报名时间2015,2017年9月广东计算机二级报名时间为6月15-30日...
  7. Delphi中DLL或Package窗体载入与显示
  8. 发现在创建云服务器ecs实例的磁盘快照时_【New Feature】阿里云快照服务技术解析...
  9. JPA / Hibernate:基于版本的乐观并发控制
  10. 【英语学习】【WOTD】disbursement 释义/词源/示例
  11. vue设置isactive_Vue 编码风格指南!
  12. 段上的等待事件 —— enq: HW - contention(oracle)
  13. mysql字段动态扩展_如何用动态字段实现系统的扩展性?
  14. verilog qpsk调制解调
  15. python风变编程是骗局吗-一个月在风变编程学完了Python基础语法,真香!
  16. es6 扩展运算符 三个点(...)
  17. flappy bird c语言,Flappy Bird C语言实现
  18. 公司为什么要融资上市?
  19. 谷歌离线版下载及vs中添加谷歌浏览器(启动项目用谷歌浏览)
  20. css实现人走路效果,纯css实现机器人走路动画

热门文章

  1. 杂项-操作系统:操作系统百科
  2. 百度收录了大量死链网址如何处理
  3. 【Qt】 Fractal Designer 5.5 Bug Report
  4. BLAST背后的知识(一点原理)
  5. 两个小时教你明白C++中类型转换关系
  6. 树莓派ADC(ADS1115)读取Voltage Sensor(电压检测模块)
  7. Django之路由层、视图层、模板层介绍
  8. 驾校网站模板 php_汽车驾照培训的网站模板
  9. 服务提供商SD-WAN市场非常广阔
  10. intersect 相交 范围_Intersect(相交)