Login.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/colors" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageButton android:id="@id/img_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:background="@drawable/quit"/><ImageView android:id="@id/iv" android:layout_height="dp" android:layout_width="dp" android:layout_marginTop="dp" android:src="@drawable/btnbg_roundcorner" android:layout_centerHorizontal="true" android:scaleType="fitXY"/> <Button android:id="@id/btn_login" android:layout_width="dip" android:layout_height="dip" android:layout_alignBottom="@id/iv" android:layout_marginBottom="dp" android:layout_toRightOf="@id/cb_mima" android:gravity="center" android:text="登录" android:textColor="#" android:textSize="sp" /> <CheckBox android:id="@id/cb_mima" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/btn_login" android:layout_alignParentLeft="true" android:text="记住密码" android:textColor="#" /> <CheckBox android:id="@id/cb_auto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/btn_login" android:layout_toRightOf="@id/btn_login" android:text="自动登录" android:textColor="#" /> <EditText android:id="@id/et_mima" android:layout_width="fill_parent" android:layout_height="dip" android:layout_above="@id/cb_mima" android:layout_centerHorizontal="true" android:layout_marginBottom="dp" android:ems="" android:maxLines="" android:password="true" android:scrollHorizontally="true" > <requestFocus /> </EditText> <TextView android:id="@id/tv_mima" android:layout_width="wrap_content" android:layout_height="dip" android:layout_above="@id/et_mima" android:layout_alignLeft="@id/et_zh" android:gravity="bottom" android:text="密码:" android:textColor="#" android:textSize="sp" /> <TextView android:id="@id/tv_zh" android:layout_width="wrap_content" android:layout_height="dip" android:layout_alignParentLeft="true" android:layout_alignTop="@id/iv" android:gravity="bottom" android:text="帐号:" android:textColor="#" android:textSize="sp" /> <EditText android:id="@id/et_zh" android:layout_width="fill_parent" android:layout_height="dip" android:layout_above="@id/tv_mima" android:layout_alignParentLeft="true" android:ems="" /> </RelativeLayout> </LinearLayout>welcome.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:background="@drawable/a" android:orientation="vertical" > <TextView android:layout_height="dp" android:layout_width="dp" android:layout_marginTop="dp" android:gravity="center" android:text="欢迎回来!" android:textColor="#A6FFFF" android:background="@drawable/btnbg_roundcorner" android:textSize="sp" /></LinearLayout>logo.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/shaohou" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="3"> <ProgressBar android:id="@id/pgBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <TextView android:id="@id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/pgBar" android:layout_centerHorizontal="true" android:text="正在登录..." android:textColor="#" android:textSize="sp" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <Button android:id="@id/btn_back" android:layout_width="dip" android:layout_height="dip" android:text="取消" android:textColor="#" android:textSize="sp" /> </LinearLayout></LinearLayout>main.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/shaohou" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="match_parent" android:textSize="sp" android:text="显示主界面" /></LinearLayout>____________________________________________________________loginActivity.javapackage com.liu.activity;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.EditText;import android.widget.ImageButton;import android.widget.Toast;public class LoginActivity extends Activity {private EditText userName, password;private CheckBox rem_pw, auto_login;private Button btn_login;private ImageButton btnQuit; private String userNameValue,passwordValue;private SharedPreferences sp;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//去掉标题this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.login); //获得实例对象sp = this.getSharedPreferences("userInfo", Context.MODE_WORLD_READABLE);userName = (EditText) findViewById(R.id.et_zh);password = (EditText) findViewById(R.id.et_mima); rem_pw = (CheckBox) findViewById(R.id.cb_mima);auto_login = (CheckBox) findViewById(R.id.cb_auto); btn_login = (Button) findViewById(R.id.btn_login); btnQuit = (ImageButton)findViewById(R.id.img_btn); //判断记住密码状态 if(sp.getBoolean("ISCHECK", false)) { //默认记录密码 rem_pw.setChecked(true); userName.setText(sp.getString("USER_NAME", "")); password.setText(sp.getString("PASSWORD", "")); //判断自动登陆状态 if(sp.getBoolean("AUTO_ISCHECK", false)) { //默认自动登录 auto_login.setChecked(true); //跳转界面Intent intent = new Intent(LoginActivity.this,LogoActivity.class);LoginActivity.this.startActivity(intent); } } // 默认为用户名为:Rome 密码:btn_login.setOnClickListener(new OnClickListener() {public void onClick(View v) {userNameValue = userName.getText().toString(); passwordValue = password.getText().toString(); if(userNameValue.equals("Rome")&&passwordValue.equals("")){Toast.makeText(LoginActivity.this,"登录成功", Toast.LENGTH_SHORT).show();//用来保存用户信息if(rem_pw.isChecked()){//记住用户名、密码 Editor editor = sp.edit(); editor.putString("USER_NAME", userNameValue); editor.putString("PASSWORD",passwordValue); editor.commit();}//跳转界面Intent intent = new Intent(LoginActivity.this,LogoActivity.class);LoginActivity.this.startActivity(intent);//finish();}else{Toast.makeText(LoginActivity.this,"用户名或密码错误,请重新登录", Toast.LENGTH_LONG).show();}}}); //监听记住密码事件rem_pw.setOnCheckedChangeListener(new OnCheckedChangeListener() {public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (rem_pw.isChecked()) { System.out.println("记住密码已选");sp.edit().putBoolean("ISCHECK", true).commit();}else {System.out.println("记住密码没有选");sp.edit().putBoolean("ISCHECK", false).commit();}}});//监听自动登录auto_login.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (auto_login.isChecked()) {System.out.println("自动登录已选");sp.edit().putBoolean("AUTO_ISCHECK", true).commit();} else {System.out.println("自动登录没有选");sp.edit().putBoolean("AUTO_ISCHECK", false).commit();}}});btnQuit.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {finish();}});}}___________________________________________________________________________logoActivity.Javapackage com.liu.activity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.widget.Button;import android.widget.ProgressBar;public class LogoActivity extends Activity {private ProgressBar progressBar;private Button backButton;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 去除标题this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.logo);progressBar = (ProgressBar) findViewById(R.id.pgBar);backButton = (Button) findViewById(R.id.btn_back);progressBar.setMax();Intent intent = new Intent(this, WelcomeAvtivity.class);LogoActivity.this.startActivity(intent);backButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {finish();}});}}__________________________________________________________________welcomeActivity.Javapackage com.liu.activity;import android.app.Activity;import android.os.Bundle;public class WelcomeAvtivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.welcome);}}
推荐整理分享记住密码与自动登录功能(记住密码自动登录 会更新登陆信息吗),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:记住密码自动登录 会更新登陆信息吗,记住密码与自动密码,记住密码与自动密码,记住密码自动登录 会更新登陆信息吗,记住密码与自动密码区别,记住密码与自动密码,记住密码自动登录,记住密码与自动密码,内容如对您有帮助,希望把文章链接给更多的朋友!
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android针对不同屏幕分辨率的4种布局适应方法 一、细说layout_weight目前最为推荐的Android多屏幕自适应解决方案。该属性的作用是决定控件在其父布局中的显示权重,一般用于线性布局中。其越小,则
Android 让EditText失去焦点避免自动弹出输入法 如果一进去activity,EditText就获取焦点,弹出输入法界面,无疑是很影响美观的。可以在其父组件(布局)上添加以下两句代码:android:focusable=trueandroid:focus
[置顶] Android各种轮子 数据库ORMLite框架