登录页面及登录测试
自己慢慢敲得登录页面及登录测试
目前没有实现与数据库的联系
<?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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"
android:gravity="center_vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:"
android:textSize="25sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入用户名或手机号"
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:background="@drawable/edit_text_bg"
android:inputType="text"
android:paddingLeft="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"
android:gravity="center_vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="25sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入密码"
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:background="@drawable/edit_text_bg"
android:inputType="textPassword"
android:paddingLeft="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<CheckBox
android:text="记住密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:text="自动登录"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"
android:textSize="25sp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textColor="@color/white"
android:background="@drawable/btn_bg_selector"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:text="还没有账号?"
android:layout_gravity="right"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"/>
</LinearLayout>
package com.example.logintest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button btnLogin;
private EditText etAccount, etPassword;
private String username="qwe";
private String mima="123";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("登录");
btnLogin = findViewById(R.id.btn_login);
etAccount = findViewById(R.id.et_account);
etPassword = findViewById(R.id.et_password);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String account =etAccount.getText().toString();
String password =etPassword.getText().toString();
if(TextUtils.equals(account,username)){
if(TextUtils.equals(password,mima)){
Toast.makeText(MainActivity.this,"恭喜你,登陆成功!",Toast.LENGTH_LONG).show();
}else {
Toast.makeText(MainActivity.this,"密码错误!",Toast.LENGTH_LONG).show();
}
}else {
Toast.makeText(MainActivity.this,"用户名错误!",Toast.LENGTH_LONG).show();
}
}
});
}
}

浙公网安备 33010602011771号