用户登录系统
来源:互联网 发布:生产数据分析报告 编辑:程序博客网 时间:2024/05/18 17:04
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.bz0209.myapplication.MainActivity"
android:background="#8ECFE5"
>
<EditText
android:hint="请输入账号"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp"
android:layout_marginTop="33dp"
android:id="@+id/textView2"
/>
<EditText
android:text="请输入密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_alignLeft="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_marginTop="10dp"
android:id="@+id/textView3" />
<CheckBox
android:text="记住密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:id="@+id/checkBox"
android:layout_alignBottom="@+id/button" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/icon_user"
android:layout_above="@+id/textView3"
android:layout_toLeftOf="@+id/textView3"
android:layout_toStartOf="@+id/textView3"
android:id="@+id/imageView" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/icon_pass"
android:layout_alignBottom="@+id/textView3"
android:layout_toLeftOf="@+id/textView3"
android:layout_toStartOf="@+id/textView3"
android:id="@+id/imageView2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/deer"
android:id="@+id/imageView3"
android:layout_below="@+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_marginTop="12dp" />
<Button
android:text="登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:id="@+id/button"
android:layout_below="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:layout_marginLeft="47dp"
android:layout_marginStart="47dp"
android:layout_alignRight="@+id/imageView3"
android:layout_alignEnd="@+id/imageView3"
android:background="@drawable/btn"
/>
</RelativeLayout>
package com.example.bz0209.myapplication;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText editText1;
private EditText editText2;
private Button button;
private CheckBox checkBox;
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intView();
sharedPreferences=getSharedPreferences("login",MODE_PRIVATE);
boolean isRem=sharedPreferences.getBoolean("checkBox",false);
if(isRem){
String name=sharedPreferences.getString("name","");
String pass=sharedPreferences.getString("pass","");
editText1.setText(name);
editText2.setText(pass);
checkBox.isChecked(true);
}
}
private void intView(){
editText1=(EditText) findViewById(R.id.textView2);
editText2=(EditText) findViewById(R.id.textView3);
button=(Button) findViewById(R.id.button);
checkBox=(CheckBox) findViewById(R.id.checkBox);
}
private void login(){
String name=editText1.getText().toString();
String pass=editText2.getText().toString();
SharedPreferences.Editor editor=sharedPreferences.edit();
if(checkBox.isChecked()){
editor.putBoolean("checkBox",true);
editor.putString("name",name);
editor.putString("pass",pass);
}
else
editor.clear();
editor.commit();
if("admin".equals(name)&&"pass".equals(pass)){
Intent intent=new Intent(this,welcome.class);
startActivity(intent);
finish();
}
else
Toast.makeText(this,"账号或密码错误",Toast.LENGTH_LONG).show();
}
package com.example.bz0209.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class welcome extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
}
<RelativeLayout 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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.bz0209.myapplication.MainActivity"
android:background="#8ECFE5"
>
<EditText
android:hint="请输入账号"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="54dp"
android:layout_marginStart="54dp"
android:layout_marginTop="33dp"
android:id="@+id/textView2"
/>
<EditText
android:text="请输入密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_alignLeft="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_marginTop="10dp"
android:id="@+id/textView3" />
<CheckBox
android:text="记住密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:id="@+id/checkBox"
android:layout_alignBottom="@+id/button" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/icon_user"
android:layout_above="@+id/textView3"
android:layout_toLeftOf="@+id/textView3"
android:layout_toStartOf="@+id/textView3"
android:id="@+id/imageView" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/icon_pass"
android:layout_alignBottom="@+id/textView3"
android:layout_toLeftOf="@+id/textView3"
android:layout_toStartOf="@+id/textView3"
android:id="@+id/imageView2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/deer"
android:id="@+id/imageView3"
android:layout_below="@+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_marginTop="12dp" />
<Button
android:text="登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:id="@+id/button"
android:layout_below="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:layout_marginLeft="47dp"
android:layout_marginStart="47dp"
android:layout_alignRight="@+id/imageView3"
android:layout_alignEnd="@+id/imageView3"
android:background="@drawable/btn"
/>
</RelativeLayout>
package com.example.bz0209.myapplication;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText editText1;
private EditText editText2;
private Button button;
private CheckBox checkBox;
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intView();
sharedPreferences=getSharedPreferences("login",MODE_PRIVATE);
boolean isRem=sharedPreferences.getBoolean("checkBox",false);
if(isRem){
String name=sharedPreferences.getString("name","");
String pass=sharedPreferences.getString("pass","");
editText1.setText(name);
editText2.setText(pass);
checkBox.isChecked(true);
}
}
private void intView(){
editText1=(EditText) findViewById(R.id.textView2);
editText2=(EditText) findViewById(R.id.textView3);
button=(Button) findViewById(R.id.button);
checkBox=(CheckBox) findViewById(R.id.checkBox);
}
private void login(){
String name=editText1.getText().toString();
String pass=editText2.getText().toString();
SharedPreferences.Editor editor=sharedPreferences.edit();
if(checkBox.isChecked()){
editor.putBoolean("checkBox",true);
editor.putString("name",name);
editor.putString("pass",pass);
}
else
editor.clear();
editor.commit();
if("admin".equals(name)&&"pass".equals(pass)){
Intent intent=new Intent(this,welcome.class);
startActivity(intent);
finish();
}
else
Toast.makeText(this,"账号或密码错误",Toast.LENGTH_LONG).show();
}
package com.example.bz0209.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class welcome extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
}
}
阅读全文
0 0
- 字典-用户登录系统
- 用户登录系统实现
- 系统登录用户表
- 模拟用户登录系统
- Java 用户登录系统
- 用户登录系统
- 电影登录系统1[用户登录]
- 用户登录系统数据库验证
- 网站用户单点登录系统
- 纯JSP用户登录系统
- debian系统root用户登录
- Tomcat 设置系统登录用户
- 纯JSP用户登录系统
- 网站系统的“用户登录”
- 用系统用户登录Oracle
- 用户登录系统 by JDBC
- debian系统root用户登录和root用户自动登录
- 网站用户单点登录系统解决方案
- linux下最好的c开发环境——codeblocks
- 电话拦截器
- 面向对象02
- 《C++ Primer》读书笔记 第13章:拷贝控制
- Android之如何判断设备是平板还是手机
- 用户登录系统
- STL中的vector容器的一点总结
- 搜索-F
- 方法
- Android Hal层简要分析
- UICollectionViewFlowLayout详解
- textView 使用HTML标签
- hihocoder1369 网络流一·Ford-Fulkerson算法
- AVFoundation