シンプルな学生情報管理システム。ログインインターフェースをクリックして登録すると、インターフェースに5つの機能が表示されます。これらの機能は、すべての学生情報の追加、削除、変更、検索、および表示です。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bj"
android:orientation="vertical">
<TextView
android:layout_marginTop="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="欢迎来到学生信息管理系统"
android:gravity="center"
android:textSize="40sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textColor="@color/colorAccent"
android:layout_marginTop="40dp"
android:id="@+id/user"
android:layout_height="wrap_content"
android:gravity="end"
android:text="请输入你的账号:"
android:textSize="30sp"
android:textStyle="bold"
android:layout_width="wrap_content">
</TextView>
<EditText
android:layout_marginTop="40dp"
android:id="@+id/input1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" " />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textColor="@color/colorAccent"
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:text="请输入你的密码:"
android:textSize="30sp"
android:textStyle="bold" />
<EditText
android:id="@+id/input2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" " />
</LinearLayout>
<LinearLayout
android:layout_marginTop="60dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:layout_height="wrap_content"
android:id="@+id/remember_button"
android:layout_width="wrap_content"
android:layout_marginLeft="50dp" />
<TextView
android:layout_marginLeft="60dp"
android:id="@+id/remember_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="是否保存本次密码"
android:textStyle="bold" />
</LinearLayout>
<ProgressBar
android:layout_marginTop="20dp"
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="250" />
<Button
android:layout_marginTop="30dp"
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:layout_marginRight="15dp"
android:background="#add8e6"
android:text="点击注册进入"
android:textSize="25sp" />
</LinearLayout>
package com.example.android;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
Button button;
EditText edit1,edit2;
CheckBox checkbox;
ProgressBar bar;
SharedPreferences pref;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button) findViewById(R.id.login_button);
edit1=(EditText) findViewById(R.id.input1);
edit2=(EditText) findViewById(R.id.input2);
checkbox=(CheckBox) findViewById(R.id.remember_button);
bar=(ProgressBar) findViewById(R.id.progress);//进度条
pref= PreferenceManager.getDefaultSharedPreferences(this);
boolean isRemember=pref.getBoolean("rem",false); //用于给是否保存密码赋值
if(isRemember) {
//将账号和密码设置到文本框中
String account=pref.getString("account","");
String password=pref.getString("password","");
edit1.setText(account);
edit2.setText(password);
checkbox.setChecked(true);
}
button.setOnClickListener(this);
}
@Override
public void onClick(View v){
String account=edit1.getText().toString();
String password=edit2.getText().toString();
if(account.equals("0417200131") && password.equals("123456789")) {
editor = pref.edit();
if(checkbox.isChecked()) {
editor.putBoolean("rem",true);
editor.putString("account",account);
editor.putString("password",password);
}
else {
editor.clear();
}
editor.commit();
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
else{
Toast.makeText(MainActivity.this,"账号或用户名错误",Toast.LENGTH_SHORT).show();
}
}
}