——注册——
activity_login.xml 注册页面设计
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:background="@color/yellow"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="OvO"
android:textColor="@color/orange"
android:textSize="35sp"
android:gravity="center"
android:layout_marginTop="100dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="30dp">
<EditText
android:id="@+id/lg_et_name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16sp"
android:textColor="@color/black"
android:hint=" 用户名"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/lg_et_password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 密 码"
android:inputType="textPassword"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/lg_et_phone"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 电话号"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/lg_et_uno"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 学生/教师"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/lg_et_id"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 学号/教师编号"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
<EditText
android:id="@+id/lg_et_classs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="16dp"
android:textColor="@color/black"
android:hint=" 班级/用户单位"
android:layout_marginTop="5dp"
android:maxLines="1"
android:background="@drawable/bg_frame"
/>
</LinearLayout>
<Button
android:id="@+id/lg_btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"
android:textColor="@color/black"
android:background="@drawable/bg_frame"
android:layout_marginLeft="2dp"
android:layout_marginTop="50dp"
/>
</LinearLayout>
LoginActivity.java 注册界面后台代码,注册成功之后会跳回到登录界面
package com.example.text002;
import static db.DBManager.getUserlogin;
import static db.DBManager.getUserstart;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
private EditText lgid, lgname, lgpassword, lgphone, lgclasss, lguno;
private Button lg_login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
lgfind();
}
private void lgfind() {
lgid = findViewById(R.id.lg_et_id);
lgname = findViewById(R.id.lg_et_name);
lgpassword = findViewById(R.id.lg_et_password);
lgphone = findViewById(R.id.lg_et_phone);
lgclasss = findViewById(R.id.lg_et_classs);
lguno = findViewById(R.id.lg_et_uno);
lg_login = findViewById(R.id.lg_btn_login);
lg_login.setOnClickListener(this);
}
@Override
public void onClick(View view) {
int lg_vid = view.getId();
if(lg_vid == R.id.lg_btn_login){
//注册
String lguid = lgid.getText().toString();
String lguname = lgname.getText().toString();
String lgupassword = lgpassword.getText().toString();
String lguphone = lgphone.getText().toString();
String lguclasss = lgclasss.getText().toString();
String lgunos = lguno.getText().toString();
// insert into user (id, name, uno, classs, phone, password)
Boolean flag = getUserlogin(lguid, lguname, lgunos, lguclasss, lguphone, lgupassword);
if(flag){
Toast.makeText(this,"注册成功OvO",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(this,"注册失败TAT",Toast.LENGTH_SHORT).show();
}
}
}
}
下一篇写登录之后
标签:lg,layout,app2,match,简单,et,android,id,记事本 From: https://www.cnblogs.com/yansans/p/17232188.html