登录页面及登录测试
自己慢慢敲得登录页面及登录测试
目前没有实现与数据库的联系
<?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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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(); } } }); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人