IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> 记事本(二) -> 正文阅读

[移动开发]记事本(二)

?设计界面

(一)界面一

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="@drawable/f5dd641ccb24f73ac133c9ec6eb1ac7"
    tools:context="com.example.jishiben.MainActivity">

    <Button
        android:id="@+id/button"
        style="@style/Widget.AppCompat.Button.Small"
        android:layout_width="142dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/transparent"
        android:shadowColor="@android:color/background_light"
        android:text="点这里!"
        android:textColor="@android:color/black"
        android:textColorHint="@android:color/background_light"
        android:textSize="30sp"
        android:textStyle="bold"
        android:typeface="normal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.168"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.109" />

</android.support.constraint.ConstraintLayout>

(二)登录界面

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="@drawable/f0b14ba475f4bd8c0a1995d9fd9affd"
    tools:context="com.example.jishiben.LoginActivity">

    <EditText
        android:id="@+id/userpass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/darker_gray"
        android:drawableLeft="@android:drawable/ic_secure"
        android:ems="10"
        android:hint="请输入密码"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.359"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.328" />

    <EditText
        android:id="@+id/username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/darker_gray"
        android:drawableLeft="@android:drawable/ic_menu_myplaces"
        android:ems="10"
        android:hint="请输入账户"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.359"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.213" />

    <TextView
        android:id="@+id/t_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="忘记密码"
        android:textColor="@android:color/background_light"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.185"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="0.492" />

    <TextView
        android:id="@+id/t_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="立即注册"
        android:textColor="@android:color/background_light"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.766"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="0.492" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="#e9d8b9"
        android:bufferType="spannable"
        android:capitalize="words"
        android:text="登录"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.467"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/userpass"
        app:layout_constraintVertical_bias="0.598" />

</android.support.constraint.ConstraintLayout>

(三)用户注册界面

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="@drawable/c72efbe1627452fbaa84f7669e6bb35"
    tools:context="com.example.jishiben.RegisterActivity">

    <TextView
        android:id="@+id/textView6"
        android:layout_width="66dp"
        android:layout_height="39dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="性别"
        android:textColor="@android:color/background_light"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.026"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.71" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="66dp"
        android:layout_height="39dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="民族"
        android:textColor="@android:color/background_light"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.026"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.554" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="82dp"
        android:layout_height="39dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="确认密码"
        android:textColor="@android:color/background_light"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.027"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.307" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="66dp"
        android:layout_height="39dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="密码"
        android:textColor="@android:color/background_light"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.059"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.162" />

    <EditText
        android:id="@+id/edt_pssConfirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.679"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.311" />

    <EditText
        android:id="@+id/edt_pss"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.679"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.164" />

    <EditText
        android:id="@+id/edt_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.679"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.017" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="66dp"
        android:layout_height="39dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="用户名"
        android:textColor="@android:color/background_light"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.059"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.032" />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="135dp"
        android:layout_height="43dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:entries="@array/minzu"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.523"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.559" />

    <RadioButton
        android:id="@+id/rd_female"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:drawableBottom="@android:drawable/btn_star"
        android:text="女"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.611"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.729" />

    <RadioButton
        android:id="@+id/rd_male"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:drawableBottom="@android:drawable/btn_star_big_on"
        android:text="男"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.401"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.729" />

    <Button
        android:id="@+id/btn_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="确定"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.15"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView6"
        app:layout_constraintVertical_bias="0.643" />

    <Button
        android:id="@+id/btn_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="返回登录"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.338"
        app:layout_constraintStart_toEndOf="@+id/btn_ok"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.939" />
</android.support.constraint.ConstraintLayout>

(四)用户忘记密码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:background="@drawable/l4140f5e7f2a329bb31d254a3d6fbfec"
    tools:context="com.example.jishiben.ModifyPassActivity">

    <TextView
        android:id="@+id/textView10"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="确认密码"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.027"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.639" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="修改密码"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.025"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.457" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="39dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="原密码"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.024"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.337" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="用户名"
        android:textColor="@android:color/background_light"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.028"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.172" />

    <EditText
        android:id="@+id/et_name"
        android:layout_width="211dp"
        android:layout_height="53dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.053"
        app:layout_constraintStart_toEndOf="@+id/textView7"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.139" />

    <EditText
        android:id="@+id/et_oldpass"
        android:layout_width="201dp"
        android:layout_height="56dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.616"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.307" />

    <EditText
        android:id="@+id/et_newpass"
        android:layout_width="208dp"
        android:layout_height="56dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.575"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.455" />

    <EditText
        android:id="@+id/et_newpass1"
        android:layout_width="215dp"
        android:layout_height="63dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.67"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/et_name"
        app:layout_constraintVertical_bias="0.58" />

    <Button
        android:id="@+id/bt_query"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/darker_gray"
        android:text="查询密码"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.11"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.885" />

    <Button
        android:id="@+id/bt_modify"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/darker_gray"
        android:text="修改密码"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.653"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.885" />
</android.support.constraint.ConstraintLayout>

代码在这~

(一)界面一——实现界面跳转

package com.example.jishiben;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button=findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,LoginActivity.class);
                startActivity(intent);

            }
        });
    }
}

(二)登陆界面

package com.example.jishiben;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText username,userpass;
    private TextView t_login,t_register;
    private Button button;
    private DBAdapter dbAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        t_register=findViewById(R.id.t_register);
        t_login=findViewById(R.id.t_login);
        username=findViewById(R.id.username);
        userpass=findViewById(R.id.userpass);
        button=findViewById(R.id.button);
        t_register.setOnClickListener(this);
        t_login.setOnClickListener(this);
        button.setOnClickListener(this);
        dbAdapter = new DBAdapter(this);
        dbAdapter.open();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.t_register:
                Intent intent=new  Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent);
                break;
            case R.id.t_login:
                Intent intent2=new Intent(LoginActivity.this,ModifyPassActivity.class);
                startActivity(intent2);
                break;
            case R.id.button:
                String name,pass;
                name=username.getText().toString();
                pass=userpass.getText().toString();
                People[] peoples = dbAdapter.queryOneData(name);
                if ( peoples == null ) {
                    Toast toast=Toast.makeText(this,"数据库中没有此用户!",Toast.LENGTH_SHORT);
                    toast.show();
                    username.setText("");
                    userpass.setText("");
                    return;
                }
                else
                {
                    if (peoples[0].Pass.equals(pass)) {
                        Toast toast=Toast.makeText(this,"登陆成功!",Toast.LENGTH_SHORT);
                        toast.show();
                        Intent intent1=new Intent(LoginActivity.this,NoteBookActivity.class);
                        intent1.putExtra("name",peoples[0].Name);
                        startActivity(intent1);
                    }
                    else {
                        Toast toast1=Toast.makeText(this,"密码输入错误!",Toast.LENGTH_SHORT);
                        toast1.show();
                        userpass.setText("");
                    }
                }


        }
    }
}

(三)注册用户

package com.example.jishiben;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity  implements View.OnClickListener{
   private EditText username,userpass1,userpass2;
   private Spinner minzu;
   private RadioButton nan,nv;
   private Button zc,dl;
   private DBAdapter dbAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        username=findViewById(R.id.edt_name);
        userpass1=findViewById(R.id.edt_pss);
        userpass2=findViewById(R.id.edt_pssConfirm);
        minzu=findViewById(R.id.spinner);
        nan=findViewById(R.id.rd_male);
        nv=findViewById(R.id.rd_female);
        zc=findViewById(R.id.btn_ok);
        dl=findViewById(R.id.btn_login);
        zc.setOnClickListener(this);
        dl.setOnClickListener(this);
        dbAdapter = new DBAdapter(this);
        dbAdapter.open();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_ok:
                People people = new People() ;
                String name,pass1,pass2,mz,sex;
                name=username.getText().toString();
                pass1=userpass1.getText().toString();
                pass2=userpass2.getText().toString();
                mz=minzu.getSelectedItem().toString();
                if(nan.isChecked())sex="男";
                else sex="女";
                if (pass1.equals(pass2)) {
                    people.Name=name;
                    people.Pass=pass1;
                    people.Minzu=mz;
                    people.Sex=sex;
                    long colum = dbAdapter.insert(people);
                    if ( colum == -1 ) {
                        Toast toast=Toast.makeText(this, "添加过程错误!!", Toast.LENGTH_SHORT);
                        toast.show();
                    } else {
                        Toast toast=Toast.makeText(this, "成功添加数据!!", Toast.LENGTH_SHORT);
                        toast.show();
                    }
                } else {
                    Toast toast=Toast.makeText(this, "两次密码输入不一致,请重新输入!!", Toast.LENGTH_SHORT);
                    toast.show();
                    userpass1.setText("");
                    userpass2.setText("");
                }
                break;
            case R.id.btn_login:
                Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
           }

        }
    }

(四)忘记密码

package com.example.jishiben;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ModifyPassActivity extends AppCompatActivity implements View.OnClickListener{
private EditText name,oldpass,newpass,newpass1;
private Button query,modify;
private DBAdapter dbAdapter ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_pass);
        name=findViewById(R.id.et_name);
        oldpass=findViewById(R.id.et_oldpass);
        newpass=findViewById(R.id.et_newpass);
        newpass1=findViewById(R.id.et_newpass1);
        query=findViewById(R.id.bt_query);
        query.setOnClickListener(this);
        modify=findViewById(R.id.bt_modify);

        modify.setOnClickListener(this);
        dbAdapter = new DBAdapter(this);
        dbAdapter.open();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_query:
                String n=name.getText().toString();
                String p;
                People[] peoples =dbAdapter.queryOneData(n);
                if (peoples == null) {
                    Toast toast= Toast.makeText(this,"用户名输入错误!",Toast.LENGTH_SHORT);
                    toast.show();
                    name.setText("");
                    return;
                }
                else
                {
                    p=peoples[0].Pass;
                    oldpass.setText(p);
                    newpass1.setEnabled(true);
                    newpass.setEnabled(true);
                }
                break;
            case R.id.bt_modify:
                String p1,p2;
                p1=newpass.getText().toString();
                p2=newpass1.getText().toString();
                if(!p1.equals(p2)) {
                    Toast toast= Toast.makeText(this,"两次密码不一致",Toast.LENGTH_SHORT);
                    toast.show();
                    newpass.setText("");
                    newpass1.setText("");
                } else {
                    People people = new People();
                    people.Name =name.getText().toString();
                    long i=dbAdapter.updateOneData(p1,people);
                    if (i == -1) {
                        Toast toast= Toast.makeText(this,"更新错误",Toast.LENGTH_SHORT);
                        toast.show();
                    }  else {
                        Toast toast= Toast.makeText(this,"更新成功",Toast.LENGTH_SHORT);
                        toast.show();
                        Intent intent=new Intent(ModifyPassActivity.this,LoginActivity.class);
                        startActivity(intent);
                    }
                }
        }
    }
}

(五)用户信息

package com.example.jishiben;

public class People {
   public int ID = -1;
   public String Name;
   public String Pass;
   public String Sex;
   public String Minzu;
   
   @Override
   public String toString(){
      String result = "";
      result += "ID:" + this.ID + ",";
      result += "姓名:" + this.Name + ",";
      result += "密码:" + this.Pass + ", ";
      result += "性别:" + this.Sex + ",";
      result += "民族:" + this.Minzu + ",";
      return result;
   }
}

values里面添加一个arrays.xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <string-array name="minzu">
            <item >汉族</item>
            <item >回族</item>
            <item >维吾尔族</item>
            <item >哈萨克族</item>
            <item >蒙古族</item>
            <item >锡伯族</item>
            <item >傣族</item>
        </string-array>
</resources>

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-12-09 11:48:03  更:2021-12-09 11:49:12 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 7:23:25-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码