implementation ‘com.squareup.okhttp3:okhttp:3.14.1’
implementation ‘com.squareup.okio:okio:2.2.2’
implementation ‘com.google.code.gson:gson:2.8.5’
复制上面代码到如图位置,然后点击右上角的Sync Now
加载
复制上面代码到如图位置
<provider
android:name=“cn.bmob.v3.util.BmobContentProvider”
android:authorities=“com.example.bmobloginservice.BmobContentProvider”>
复制上面代码到如图位置,并将图中小方形的代码修改为你自己的包名
Bmob的配置工作到这里就结束了,接下来就是敲代码了······
一、数据表
首先我们创建一个类,类名自己取(到时候在自动Bmob后台会创建一个和类名一样的表),继承BmobObject类
package com.example.bmobloginservice;
import cn.bmob.v3.BmobObject;
public class User_Table extends BmobObject {
//账号
private String Account;
//密码
private String Password;
public String getAccount() {
return Account;
}
public void setAccount(String account) {
Account = account;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
}
表数据有Account
账号、Password
密码两个字段
二、工具类
新建一个Check类,创建两个方法用于号码检测(PhoneCheck)和密码检测(PasswordCheck)
号码检测
判断输入的收集号码是否满足国内号码的要求
密码检测
判断输入的密码是否满足要求(最少有3个字母)
package com.example.bmobloginservice;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Check {
/**
-
手机号码检测
-
@param phone:输入的号码
-
@return true -->>号码正确,false–>>号码不正确
*/
public static boolean PhoneCheck(String phone){
String ChineseMainland = “^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])” + “|(18[0-9])|(19[8,9]))\d{8}$”;
String HongKong = “^(5|6|8|9)\d{7}$”;
Matcher C = Pattern.compile(ChineseMainland).matcher(phone);
Matcher H = Pattern.compile(HongKong).matcher(phone);
return C.matches() || H.matches();
}
/**
-
密码检测(是否符合最少3个字母的要求)
-
@param password:输入的密码
-
@return true–>>密码格式正确,false–>>密码格式不正确
*/
public static boolean PasswordCheck(String password){
char[] s = password.toCharArray();
int count=0;
for (int i = 0; i < s.length; i++) {
if ((s[i]>=‘a’&&s[i]<=‘z’) || (s[i]>=‘A’&&s[i]<=‘Z’)){
count++;
}
}
if (count>=3){
return true;
}else {
return false;
}
}
}
一、注册模块
布局文件
drawable
包下的button_bg布局文件的代码
res
包下的register布局文件的代码
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“@mipmap/background”>
<EditText
android:id=“@+id/AccountText”
android:layout_width=“300dp”
android:layout_height=“50dp”
android:layout_marginTop=“175dp”
android:ems=“10”
android:hint=“手机号码”
android:textSize=“16dp”
android:drawableLeft=“@mipmap/account”
android:drawablePadding=“10dp”
android:inputType=“textPersonName”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toTopOf=“parent” />
<EditText
android:id=“@+id/PasswordText”
android:layout_width=“300dp”
android:layout_height=“45dp”
android:layout_marginTop=“30dp”
android:ems=“10”
android:hint=“密码由6~16位组成(最少3位字母)”
android:textSize=“16dp”
android:drawableLeft=“@mipmap/psd”
android:drawablePadding=“10dp”
android:inputType=“textPassword”
app:layout_constraintStart_toStartOf=“@+id/AccountText”
app:layout_constraintTop_toBottomOf=“@+id/AccountText” />
<Button
android:id=“@+id/RegisterButton”
android:layout_width=“200dp”
android:layout_height=“60dp”
android:layout_marginTop=“100dp”
android:background=“@drawable/button_bg”
android:text=“注册”
android:textSize=“25dp”
app:layout_constraintTop_toBottomOf=“@+id/PasswordText”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”/>
<TextView
android:id=“@+id/RegisterTitle”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginBottom=“60dp”
android:text=“Register”
android:textSize=“40dp”
app:layout_constraintBottom_toTopOf=“@+id/AccountText”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent” />
<TextView
android:id=“@+id/LoginButton”
android:layout_width=“wrap_conte