/**

 * 

 * @author alex

 * @version 2014-7-31下午5:25:45

 *

 */

public class LoginActivity extends Activity {

private EditText name;

private EditText pass;

private CheckBox isRemenber;

private CheckBox isLoginSelf;

private Button longin;

private ProgressDialog mDialog;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        name=(EditText)findViewById(R.id.et_name);

        pass=(EditText)findViewById(R.id.et_pass);

        isRemenber=(CheckBox)findViewById(R.id.isremenber);

        isLoginSelf=(CheckBox)findViewById(R.id.isloginself);

        longin=(Button)findViewById(R.id.longin);

        

        final SharedPreferences pre=getSharedPreferences("longinvalue", MODE_WORLD_WRITEABLE);

        if(pre!=null){

        //记住了password

           if(pre.getBoolean("isrmb", false)==true){

          name.setText(pre.getString("name", null));

          pass.setText(pre.getString("pass", null));

          isRemenber.setChecked(true) ;

           }

           if(pre.getBoolean("islgs", false)==true){

          isLoginSelf.setChecked(true);

          creatDialog();

          new Thread(){

          public void run() {

          try {





Thread.sleep(3000);

       if(mDialog.isShowing()){

     mDialog.dismiss();

     }

Intent intent2=new Intent(LoginActivity.this,Show.class);

startActivity(intent2);

} catch (Exception e) {

// TODO: handle exception

}

          }

          }.start();

           }

        }

        isRemenber.setOnCheckedChangeListener( new OnCheckedChangeListener() {



@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

// TODO Auto-generated method stub

     if(isRemenber.isChecked()==false){

     isLoginSelf.setChecked(false);

     }

}

});

        isLoginSelf.setOnCheckedChangeListener(new OnCheckedChangeListener() {



@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

// TODO Auto-generated method stub

 isRemenber.setChecked(true);

}

});

        longin.setOnClickListener(new OnClickListener() {



@Override

public void onClick(View v) {

// TODO Auto-generated method stub

if(!name.getText().toString().equals("")&&!pass.getText().toString().equals("")){

if(isLoginSelf.isChecked()){

pre.edit().putBoolean("isrmb", true).putBoolean("islgs", true).putString("name", name.getText().toString())

.putString("pass", pass.getText().toString()).commit();

}else{

if(isRemenber.isChecked()){

pre.edit().putBoolean("isrmb", true).putBoolean("islgs", false).putString("name", name.getText().toString())

.putString("pass", pass.getText().toString()).commit();

}else{

pre.edit().putBoolean("isrmb", false).putBoolean("islgs", false).putString("name", name.getText().toString())

.putString("pass", pass.getText().toString()).commit();

}

}

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

startActivity(intent);

}else{

Toast.makeText(getApplicationContext(), "password或账号不能为空!", Toast.LENGTH_LONG).show();

}





}

});

    }

    private void creatDialog() {

     mDialog=new ProgressDialog(this);

     mDialog.setTitle("验证中");

     mDialog.setMessage("正在登陆请稍后");

     mDialog.setIndeterminate(true);

     mDialog.setCancelable(true);

     mDialog.show();

      

}

}

import android.app.Activity;

import android.os.Bundle;





public class Show extends Activity{

  @Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.show);

}

}

<?

xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="alex.sias.com"

    android:versionCode="1"

    android:versionName="1.0" >





    <uses-sdk android:minSdkVersion="8" />





    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >

    </uses-permission>





    <application

        android:icon="@drawable/icon"

        android:label="@string/app_name"

        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

        <activity

            android:name=".LoginActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />





                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity android:name="Show" >

        </activity>

    </application>





</manifest>

用到两个布局文件

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="@drawable/chat_bg_default"

    >

    <TextView 

    android:layout_height="50dp"

    android:layout_width="fill_parent"

    android:gravity="center"

    android:textSize="24sp"

    android:text="登录界面"

    android:textColor="@color/white"

    android:background="@drawable/song_index_item_bg"/>

    <ImageView 

    android:id="@+id/iv"

    android:layout_height="220dp"

    android:layout_width="230dp"

    android:layout_marginTop="110dp"

    android:src="@drawable/background"

    android:layout_centerHorizontal="true"

    android:scaleType="fitXY"/>

    <TextView 

    android:id="@+id/tv_name"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:textSize="15sp"

    android:layout_marginTop="7dp"

    android:text="账号:"

    android:layout_alignLeft="@+id/iv"

    android:layout_alignTop="@+id/iv"

    android:layout_marginLeft="7dp"

    android:textColor="@color/green"/>

    <EditText 

    android:id="@+id/et_name"

    android:layout_height="25dp"

    android:layout_width="210dp"

    android:layout_marginTop="7dp"

    android:layout_below="@+id/tv_name"

    android:background="@drawable/shape"

    android:layout_alignLeft="@+id/tv_name"/>

    <TextView 

    android:id="@+id/tv_pass"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:textSize="15sp"

    android:text="password:"

    android:layout_alignLeft="@+id/tv_name"

    android:layout_below="@+id/et_name"

    android:layout_marginTop="7dp"

    android:textColor="@color/green"/>

    <EditText 

    android:id="@+id/et_pass"

    android:layout_height="25dp"

    android:layout_width="210dp"

    android:background="@drawable/shape"

    android:layout_marginTop="7dp"

    android:layout_below="@+id/tv_pass"

    android:layout_alignLeft="@+id/tv_name"/>

    <CheckBox 

    android:id="@+id/isremenber"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:layout_alignLeft="@+id/tv_name"

    android:layout_marginTop="10dp"

    android:text="记住password"

    android:textSize="11sp"

    android:textColor="@color/huise"

    android:layout_below="@+id/et_pass"

    android:button="@drawable/mycheckbox"/>

    <CheckBox 

    android:id="@+id/isloginself"

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:layout_alignRight="@+id/et_name"

    android:layout_marginTop="10dp"

    android:text="自己主动登录"

    android:textSize="11sp"

    android:textColor="@color/huise"

    android:layout_below="@+id/et_pass"

    android:button="@drawable/mycheckbox"/>

    <Button 

    android:id="@+id/longin"

    android:layout_height="25dp" 

    android:layout_width="210dp"

    android:layout_below="@+id/isloginself"

    android:layout_alignLeft="@+id/et_pass"

    android:layout_marginTop="10dp"

    android:text="登录"

    android:gravity="center"

    android:background="@drawable/loginbtn"/>

</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

  xmlns:android="http://schemas.android.com/apk/res/android"

  android:orientation="vertical"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:background="@color/white">

  <TextView 

  android:layout_height="fill_parent"

  android:layout_width="fill_parent"

  android:text="嘿嘿!"

  android:textSize="40sp"

  android:gravity="center"/>

    

</LinearLayout>

Android记住password后自己主动登录的更多相关文章

  1. 危急,不要任意让站点记住password自己主动登陆!

    为了方便用户登录,差点儿全部的站点都实现了"记住password"."自己主动登陆"这样似乎人性化的功能. 我也非常喜欢这个功能,由于我自己的脑子实在是讨厌记东 ...

  2. Chrome浏览器记住密码后input框黄色背景且背景图片不显示的问题

    Chrome浏览器记住密码后再进入登录页后,输入框背景颜色变为黄色,字体颜色变成#000黑色,且添加的背景图片也那不显示了,进入审查元素后,发现浏览器默认给输入框添加了样式,并且无法通过importa ...

  3. 下次自己主动登录(记住password)功能

    1:进入cookie插件 <script src="jquery.cookie.js" type="text/javascript"></sc ...

  4. 记住密码后,密码框Password会自动带出数据

    一般登陆之后浏览器会询问是否记住密码,如果把密码记住在浏览器上,下次登陆的时候浏览器会把用户名和密码自动填充到登录页面.前段时间服务站平台的员工账号模块提测后,测试提出360浏览器记住密码后会自用把登 ...

  5. 用了一天的时间,linux下expect实现ssh自己主动登录server记,歧视下网上各种抄来抄去残段子

    由于要对客户方的快30个项目进行特别有顺序的重新启动,所以不得不想办法写个脚本,网上看了不少段子.真是残缺的能够. 没有一段是能够正常运行的.我来按顺序记录一下 脚本的本身 使用expect实现自己主 ...

  6. Android:利用SharedPreferences实现自动登录

    主要代码: public class LoginActivity extends Activity { private EditText username; private EditText user ...

  7. Python3.x爬虫教程:爬网页、爬图片、自己主动登录

    林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 摘要:本文将使用Python3.4爬网页.爬图片.自己主动登录.并对HTTP协议做了一个简单 ...

  8. [IOS NSUserDefaults]的使用:登陆后不再显示登录界面。

    之前搜了好多地方都没找到实现“登陆后不再显示登录界面,而默认自动登录”的方法. 待我发现有种存储方式叫NSUserDefaults的时候,立马又感觉新技能get了. 简介: NSUserDefault ...

  9. linux安装mysql后root无法登录 sql 无法登录

    linux安装mysql后root无法登录 问题:[root@localhost mysql]# mysql -u root -pEnter password: ERROR 1045 (28000): ...

随机推荐

  1. Spark(九) -- SparkSQL API编程

    本文测试的Spark版本是1.3.1 Text文本文件测试 一个简单的person.txt文件内容为: JChubby,13 Looky,14 LL,15 分别是Name和Age 在Idea中新建Ob ...

  2. Splunk 会议回想: 大数据的关键是机器学习

    作者 Jonathan Allen ,译者 张晓鹏 Splunk的用户大会已经接近尾声.三天时间的会议里,共进行了160多个主题研讨.涵盖了从安全.运营到商业智能.甚至包含物联网,会议中一遍又一遍出现 ...

  3. 在FASTBuild中使用Distribution

    上一篇:在FASTBuild中使用Caching 在FASTBuild中使用分布式(distribution)编译需要注意以下四个环节. 一.编译器设置 某些编译过程与分布式相矛盾,如果一个对象不能被 ...

  4. jQuery (样式篇)

    1.$(document).ready 的作用是等页面的文档(document)中的节点都加载完毕后,再执行后续的代码,因为我们在执行代码的时候,可能会依赖页面的某一个元素,我们要确保这个元素真正的的 ...

  5. 神秘值分解(Singular Value Decomposition)

    - 线性变化的几何表现 首先看下简单的矩阵,这是一个对角矩阵 M=(3001) 我们先用这个对角矩阵乘以一个点来看看它的几何变化. (3001)∗(xy)=(3xy) 在几何上就相当于把原来的向量x轴 ...

  6. Android短信发送器(2)

    在上一篇的<Android短信发送器>当中.发送功能并不完好.当发送内容超过限定字数时,短信就会发送失败,此时就须要推断内容是否超过限制,假设不超过限制.就直接发送,反之.则对其进行处理再 ...

  7. Asp.Net WebApi服务端解决跨域方案

    1.特性方式 主要是继承ActionFilterAttribute,重写OnActionExecuted方法,在action执行后,给响应头加上一个键值对. using System.Web.Http ...

  8. 使用svn hooks 脚本post-commit时遇到的故障

    由于网站上线,需要把新添加功能上传到测试环境进行测试,但由于程序员每天有大量的修改,如果总是登陆服务器手动更新svn工作副本(测试环境)太耗时耗精力,进而增加svn进行commit时,测试环境即时更新 ...

  9. C# JSON序列化日期格式问题

    默认序列化日期为1970至今的时间戳 需要在json.convert中做一些设置 //JavaScriptSerializer js = new JavaScriptSerializer(); Iso ...

  10. cadence原理图和PCB互联显示成功但是不能高亮和database

    问题现象:cadence原理图和PCB互联显示成功但是不能高亮我的问题 解决:尝试修复数据库试试,Tools->Database check 提醒:有一个封装非法命名,在原理图中修改后 再次保存 ...