安卓studio 个人课设项目:“这个app“——实现注册登录,显示用户信息功能,并跳转对应网页

编程之家收集整理的这篇文章主要介绍了安卓studio 个人课设项目:“这个app“——实现注册登录,显示用户信息功能,并跳转对应网页编程之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目录

功能说明 

登录页面

注册页面

登录后界面

点击头像出现侧滑界面,并显示用户信息

点击编辑按钮进入信息编辑页面

 保存后返回

 用户名已更改

跳转网页

相关代码

布局

登录界面

 注册界面

 信息显示界面

 主界面

实现侧滑布局 

信息编辑界面

网页显示界面 

manifest 

逻辑代码 

 LoginActivity

RegisterActivity

EditInformationActivity

RelaxActivity

StudyActivity

SlideActivity

实现侧滑功能

网页activity

网页配置——SetWebView.class

 进度条加载——SetProgressBar.class

 数据库helper

user类

ToastUtil

结语


功能说明 

登录页

注册页面

能够验证用户名是否已存在,并判断两次密码是否一致

 

登录后界面

点击头像出现侧滑界面,并显示用户信息

当前用户无信息

 

点击编辑按钮进入信息编辑页面

编辑信息

 

 保存后返回

信息页面显示更改后的信息

 用户名已更改

修改用户名后,下次登录需要填写更改后的用户名

@H_301_133@

跳转网页

点击按钮进入相应的网页这里点击  “长知识”>>“菜鸟学编程”

 

相关代码

布局

登录界面

<?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:background="@drawable/bg_blue_orange"
    androID:orIEntation="vertical"
    tools:context=".LoginActivity">

    <TextVIEw
        androID:ID="@+ID/textVIEw"
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:gravity="center"
        androID:layout_margintop="100dp"
        androID:text="欢迎使用这个app!"
        androID:textcolor="@color/white"
        androID:textSize="20sp" />

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:layout_marginHorizontal="30dp"
        androID:layout_margintop="80dp"
        androID:background="@drawable/bt_humditiy"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw10"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="3"
            androID:text="用户名:"
            androID:textcolor="@color/white"
            androID:layout_marginleft="5dp"
            androID:textSize="18dp" />

        <EditText
            androID:ID="@+ID/Ed_username"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:hint="@string/input_username"
            androID:inputType="textPersonname"
            androID:textcolor="@color/white" />
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:layout_marginHorizontal="30dp"
        androID:layout_margintop="30dp"
        androID:background="@drawable/bt_humditiy"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw11"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="3"
            androID:text="密码:"
            androID:textcolor="@color/white"
            androID:layout_marginleft="5dp"
            androID:textSize="18dp" />

        <EditText
            androID:ID="@+ID/Ed_password"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:ems="10"
            androID:hint="@string/input_password"
            androID:inputType="textPassword"
            androID:textcolor="@color/white"
            androID:textcolorHighlight="@color/white" />
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:layout_margintop="80dp"
        androID:orIEntation="horizontal">

        <button
            androID:ID="@+ID/bt_login"
            androID:layout_wIDth="0dp"
            androID:layout_weight="1"
            androID:layout_height="wrap_content"
            androID:layout_gravity="center"
            androID:background="@drawable/bt_humditiy"
            androID:text="@string/login"
            androID:textcolor="@color/white"
            androID:layout_marginleft="20dp"
            androID:layout_marginRight="20dp"
            androID:textSize="20sp" />

        <button
            androID:ID="@+ID/bt_register"
            androID:layout_wIDth="0dp"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:background="@drawable/bt_humditiy"
            androID:text="@string/registered"
            androID:textcolor="@color/white"
            androID:layout_marginRight="20dp"
            androID:layout_marginleft="20dp"
            androID:textSize="24sp" />
    </linearLayout>

</linearLayout>

 注册界面

<?xml version="1.0" enCoding="utf-8"?>
<androIDx.constraintlayout.Widget.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/bg_blue_orange"
    tools:context=".Registeractivity">

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="match_parent"
        androID:orIEntation="vertical">

        <TextVIEw
            androID:ID="@+ID/register_Title"
            androID:layout_wIDth="wrap_content"
            androID:layout_height="wrap_content"
            androID:text="注册"
            androID:textSize="40dp"
            androID:textcolor="@color/white"
            androID:layout_margintop="20dp"
            androID:layout_marginStart="160dp"/>

        <linearLayout
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margintop="120dp"
            androID:background="@drawable/bt_humditiy"
            androID:layout_marginHorizontal="20dp"
            androID:orIEntation="horizontal">

            <TextVIEw
                androID:ID="@+ID/textVIEw7"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="3"
                androID:textcolor="@color/white"
                androID:textSize="18dp"
                androID:layout_marginleft="5dp"
                androID:text="用户名:" />

            <EditText
                androID:ID="@+ID/set_username"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="1"
                androID:ems="10"
                androID:hint="请输入用户名:"
                androID:inputType="textPersonname" />
        </linearLayout>

        <linearLayout
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margintop="20dp"
            androID:background="@drawable/bt_humditiy"
            androID:layout_marginHorizontal="20dp"
            androID:orIEntation="horizontal">

            <TextVIEw
                androID:ID="@+ID/textVIEw8"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="3"
                androID:textcolor="@color/white"
                androID:textSize="18dp"
                androID:layout_marginleft="5dp"
                androID:text="密码:" />

            <EditText
                androID:ID="@+ID/set_userPassword1"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="1"
                androID:ems="10"
                androID:hint="请输入密码:"
                androID:inputType="textPassword" />
        </linearLayout>

        <linearLayout
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margintop="20dp"
            androID:background="@drawable/bt_humditiy"
            androID:layout_marginHorizontal="20dp"
            androID:orIEntation="horizontal">

            <TextVIEw
                androID:ID="@+ID/textVIEw9"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="3"
                androID:textcolor="@color/white"
                androID:textSize="18dp"
                androID:layout_marginleft="5dp"
                androID:text="确认密码:" />

            <EditText
                androID:ID="@+ID/set_userPassword2"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="1"
                androID:ems="10"
                androID:hint="再次输入密码:"
                androID:inputType="textPassword" />
        </linearLayout>

        <button
            androID:ID="@+ID/bt_startRegister"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margintop="80dp"
            androID:layout_marginHorizontal="100dp"
            androID:background="@drawable/bt_humditiy"
            androID:textcolor="@color/white"
            androID:textSize="20dp"
            androID:text="点击注册" />
    </linearLayout>

</androIDx.constraintlayout.Widget.ConstraintLayout>

 信息显示界面

<?xml version="1.0" enCoding="utf-8"?>
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"
    androID:layout_wIDth="270dp"
    androID:layout_height="match_parent"
    androID:orIEntation="vertical"
    androID:background="@drawable/bg_purple_miror">

    <TextVIEw
        androID:ID="@+ID/tv_userinformation"
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:gravity="center"
        androID:text="个人信息"
        androID:textcolor="@color/white"
        androID:textSize="25dp" />

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/tv_age"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margintop="20dp"
            androID:layout_weight="3"
            androID:text="年龄:"
            androID:textcolor="@color/white"
            androID:textSize="22dp" />

        <TextVIEw
            androID:ID="@+ID/tv_userAge"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:textcolor="@color/white"
            androID:layout_weight="1"
            androID:textSize="22dp"
            androID:layout_margintop="20dp"
            androID:text="TextVIEw" />

    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:layout_margintop="20dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/tv_sex"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="3"
            androID:text="性别:"
            androID:textcolor="@color/white"
            androID:textSize="22dp" />

        <TextVIEw
            androID:ID="@+ID/tv_userSex"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:textcolor="@color/white"
            androID:textSize="22dp"
            androID:text="TextVIEw" />
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:layout_margintop="20dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/tv_favorite"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="3"
            androID:text="爱好:"
            androID:textcolor="@color/white"
            androID:textSize="22dp" />

        <TextVIEw
            androID:ID="@+ID/tv_userFavorite"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:textcolor="@color/white"
            androID:textSize="22dp"
            androID:text="TextVIEw" />

    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="200dp"
        androID:layout_margintop="20dp"
        androID:orIEntation="vertical">

        <TextVIEw
            androID:ID="@+ID/tv_signature"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:text="个性签名:"
            androID:textcolor="@color/white"
            androID:textSize="20dp" />

        <TextVIEw
            androID:ID="@+ID/tv_userSignature"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="9"
            androID:textcolor="@color/white"
            androID:textSize="22dp"
            androID:text="TextVIEw" />

    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:orIEntation="vertical">

        <button
            androID:ID="@+ID/bt_toEdit"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margintop="200dp"
            androID:background="@color/bitGrey"
            androID:paddingleft="180dp"
            androID:text="编辑>"
            androID:textcolor="@color/white"
            androID:textSize="30dp" />
    </linearLayout>

</linearLayout>

 主界面

<?xml version="1.0" enCoding="utf-8"?>
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"
    androID:layout_wIDth="match_parent"
    androID:layout_height="match_parent"
    androID:orIEntation="vertical"
    androID:background="@drawable/bg_purple">

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="60dp"
        androID:layout_margintop="10dp">

        <ImageVIEw
            androID:ID="@+ID/iv_head"
            androID:layout_wIDth="60dp"
            androID:layout_height="wrap_content"
            androID:src="@mipmap/head1"
            androID:layout_margintop="5dp"
            androID:layout_marginleft="10dp"
            androID:scaleType="centerCrop"/>

        <TextVIEw
            androID:ID="@+ID/tv_username"
            androID:layout_wIDth="wrap_content"
            androID:layout_height="match_parent"
            androID:text="user_冰川"
            androID:textSize="30dp"
            androID:layout_margin="10dp"
            androID:textcolor="@color/white"/>
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:padding="15dp"
        androID:layout_margintop="200dp"
        androID:orIEntation="vertical">

        <button
            androID:ID="@+ID/btn_study"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margin="40dp"
            androID:text="长知识"
            androID:background="@drawable/bt_humditiy"
            androID:textcolor="@color/white"/>

        <button
            androID:ID="@+ID/btn_relax"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_margin="40dp"
            androID:text="找点乐子"
            androID:background="@drawable/bt_humditiy"
            androID:textcolor="@color/white"/>

    </linearLayout>

</linearLayout>

实现侧滑布局 

<?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=".SlIDeActivity">

    <com.example.myfirst.util.SlIDeMenu
        androID:ID="@+ID/slIDeMenu"
        androID:layout_wIDth="wrap_content"
        androID:layout_height="wrap_content">

        <!--        信息界面布局-->
        <include layout="@layout/layout_menu" />

        <!--        主界面布局-->
        <include
            layout="@layout/layout_main"
            androID:layout_wIDth="wrap_content"
            androID:layout_height="743dp" />
    </com.example.myfirst.util.SlIDeMenu>

</linearLayout>

信息编辑界面

<?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:background="@drawable/bg_green_blue"
    tools:context=".EditinformationActivity">

    <TextVIEw
        androID:ID="@+ID/Tv_Editinformation"
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:gravity="center"
        androID:text="信息编辑"
        androID:textcolor="@color/white"
        androID:textSize="30sp" />

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:background="@color/bitGrey"
        androID:layout_margintop="120dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw2"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="2"
            androID:textcolor="@color/white"
            androID:textSize="25dp"
            androID:layout_marginleft="10dp"
            androID:text="用户名:" />

        <EditText
            androID:ID="@+ID/Et_EditUsername"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:ems="10"
            androID:inputType="textPersonname"
            androID:textcolor="@color/white"
            androID:textSize="20dp" />
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:background="@color/bitGrey"
        androID:layout_margintop="20dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw3"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="2"
            androID:textcolor="@color/white"
            androID:textSize="25dp"
            androID:layout_marginleft="10dp"
            androID:text="年龄:" />

        <EditText
            androID:ID="@+ID/Et_editAge"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:ems="10"
            androID:inputType="textPersonname"
            androID:textcolor="@color/white"
            androID:textSize="20dp" />
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:background="@color/bitGrey"
        androID:layout_margintop="20dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw4"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="2"
            androID:textcolor="@color/white"
            androID:textSize="25dp"
            androID:layout_marginleft="10dp"
            androID:text="性别:" />

        <RadioGroup
            androID:ID="@+ID/rg_sex"
            androID:layout_wIDth="match_parent"
            androID:layout_height="match_parent"
            androID:orIEntation="horizontal"
            androID:layout_weight="1">

            <Radiobutton
                androID:ID="@+ID/rdB_male"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="1"
                androID:text="男" />

            <Radiobutton
                androID:ID="@+ID/rdB_female"
                androID:layout_wIDth="match_parent"
                androID:layout_height="wrap_content"
                androID:layout_weight="1"
                androID:text="女" />

        </RadioGroup>

    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:background="@color/bitGrey"
        androID:layout_margintop="20dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw5"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="2"
            androID:textcolor="@color/white"
            androID:textSize="25dp"
            androID:layout_marginleft="10dp"
            androID:text="爱好:" />

        <EditText
            androID:ID="@+ID/Et_editFavorite"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:ems="10"
            androID:inputType="textPersonname"
            androID:textcolor="@color/white"
            androID:textSize="20dp" />
    </linearLayout>

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:background="@color/bitGrey"
        androID:layout_margintop="20dp"
        androID:orIEntation="horizontal">

        <TextVIEw
            androID:ID="@+ID/textVIEw6"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="2"
            androID:textcolor="@color/white"
            androID:textSize="25dp"
            androID:layout_marginleft="10dp"
            androID:text="个性签名:" />

        <EditText
            androID:ID="@+ID/Et_editSignature"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content"
            androID:layout_weight="1"
            androID:ems="10"
            androID:inputType="textPersonname"
            androID:textcolor="@color/white"
            androID:textSize="20dp" />
    </linearLayout>
    <button
        androID:ID="@+ID/bt_saveinformation"
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        androID:layout_margintop="100dp"
        androID:layout_marginHorizontal="100dp"
        androID:background="@drawable/bt_humditiy"
        androID:textcolor="@color/white"
        androID:textSize="30dp"
        androID:text="保存" />


</linearLayout>

网页显示界面 

<?xml version="1.0" enCoding="utf-8"?>
<androIDx.constraintlayout.Widget.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"
    tools:context=".RunoobActivity">

    <linearLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="match_parent"
        androID:orIEntation="vertical">

        <Progressbar
            androID:ID="@+ID/pb_run_oob"
            style="?androID:attr/progressbarStyleHorizontal"
            androID:max="100"
            androID:layout_wIDth="match_parent"
            androID:layout_height="wrap_content" />

        <WebVIEw
            androID:ID="@+ID/wv_runOob"
            androID:layout_wIDth="match_parent"
            androID:layout_height="match_parent" />
    </linearLayout>
</androIDx.constraintlayout.Widget.ConstraintLayout>

manifest 

<?xml version="1.0" enCoding="utf-8"?>
<manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"
    package="com.example.myfirst">

    <uses-permission androID:name="androID.permission.INTERNET" />

    <application
        androID:allowBackup="true"
        androID:icon="@mipmap/this_app"
        androID:label="@string/app_name"
        androID:roundIcon="@mipmap/this_app"
        androID:supportsRtl="true"
        androID:theme="@style/theme.Myfirst"
        androID:usesCleartextTraffic="true">
        <activity
            androID:name=".FlowerActivity"
            androID:exported="false" />
        <activity
            androID:name=".EndlessLakeActivity"
            androID:exported="false" />
        <activity
            androID:name=".SpaceActivity"
            androID:exported="false" />
        <activity
            androID:name=".DeepSeaActivity"
            androID:exported="false" />
        <activity
            androID:name=".AnswerActivity"
            androID:exported="false" />
        <activity
            androID:name=".MedicineActivity"
            androID:exported="false" />
        <activity
            androID:name=".TechnologyMuseumActivity"
            androID:exported="false" />
        <activity
            androID:name=".RunoobActivity"
            androID:exported="false" />
        <activity
            androID:name=".EditinformationActivity"
            androID:exported="false" />
        <activity
            androID:name=".Registeractivity"
            androID:exported="false" /> <!-- 防止net::ERR_CLEARTEXT_NOT_PERMITTED -->
        <activity
            androID:name=".WhichoneActivity"
            androID:exported="false" />
        <activity
            androID:name=".LoopTapActivity"
            androID:exported="false" />
        <activity
            androID:name=".HenxiangsiActivity"
            androID:exported="false" />
        <activity
            androID:name=".MikutapActivity"
            androID:exported="false" />
        <activity
            androID:name=".SummondragonActivity"
            androID:exported="false" />
        <activity
            androID:name=".EatwhatActivity"
            androID:exported="false" />
        <activity
            androID:name=".WebZTypeActivity"
            androID:exported="false" />
        <activity
            androID:name=".RelaxActivity"
            androID:exported="false" />
        <activity
            androID:name=".StudyActivity"
            androID:exported="false" />
        <activity
            androID:name=".SlIDeActivity"
            androID:exported="true" />
        <activity
            androID:name=".LoginActivity"
            androID:exported="true">
            <intent-filter>
                <action androID:name="androID.intent.action.MAIN" />

                <category androID:name="androID.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

逻辑代码 

 LoginActivity

package com.example.myfirst;

import androIDx.appcompat.app.AppCompatActivity;

import androID.content.Intent;
import androID.os.Bundle;
import androID.text.TextUtils;
import androID.vIEw.VIEw;
import androID.Widget.button;
import androID.Widget.EditText;

import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.ToastUtil;
import com.example.myfirst.util.User;

import java.util.ArrayList;

public class LoginActivity extends AppCompatActivity implements VIEw.OnClickListener {
                                 //当需要用到新的onClick()时,要 implements VIEw.OnClickListener
    private button mBtLogin;            //声明变量
    private EditText mEtUser;
    private EditText mEtPassword;
    private button mBtRegister;
    private DBHelper dbHelper;
    public static int userID;

    @OverrIDe
    protected voID onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.activity_login);

        mBtLogin = findVIEwByID(R.ID.bt_login);
        mEtPassword = findVIEwByID(R.ID.Ed_password);
        mEtUser = findVIEwByID(R.ID.Ed_username);
        mBtRegister = findVIEwByID(R.ID.bt_register);

        dbHelper = new DBHelper(this);
        mBtLogin.setonClickListener(this);       //当需要用到新的onClick()时,就用this
        mBtRegister.setonClickListener(this);
    }

    public voID onClick(VIEw vIEw){
        switch (vIEw.getID()){
            case R.ID.bt_login:
                String username = mEtUser.getText().toString().trim();
                String password = mEtPassword.getText().toString().trim();

                if(!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)){
                    ArrayList<User> userData = dbHelper.getData();  //在User List创建一个实例userData
                    boolean judge = false;                          //并让userData获取数据库里的数据
                    for (int i = 0; i < userData.size(); i++){
                        User user = userData.get(i);
                        if (username.equals(user.getname()) && password.equals(user.getpassword())){
                            judge = true;
                            userID = i;
                            break;
                        }              //遍历user ID,当输入的用户名和密码与数据库里的数据匹配则judge=true
                        else {
                            judge = false;
                        }
                    }
                    if (judge){
                        ToastUtil.showMsg(LoginActivity.this,"登陆成功!");
                        Intent intent2 = new Intent(this,SlIDeActivity.class);
                        startActivity(intent2);
                        finish();
                    }
                    else {
                        ToastUtil.showMsg(LoginActivity.this,"用户名错误或密码错误!");
                    }
                }
                else {
                    ToastUtil.showMsg(LoginActivity.this,"用户名或密码不能为空");
                }
                break;
            case R.ID.bt_register:
                Intent intent1 = new Intent(LoginActivity.this,Registeractivity.class);
                startActivity(intent1);
                break;
        }
    }
    public  static int getUserID(){
        return userID;
    }
}

Registeractivity

package com.example.myfirst;

import androIDx.appcompat.app.AppCompatActivity;

import androID.content.Intent;
import androID.os.Bundle;
import androID.text.TextUtils;
import androID.vIEw.VIEw;
import androID.Widget.button;
import androID.Widget.EditText;

import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.ToastUtil;

public class Registeractivity extends AppCompatActivity implements VIEw.OnClickListener{

    private button mBtToRegister;
    private DBHelper dbHelper;
    private EditText mEtSetUsername;
    private EditText mEtSetUserPassword1;
    private EditText mEtSetUserPassword2;

    @OverrIDe
    protected voID onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.activity_register);

        mEtSetUsername = findVIEwByID(R.ID.set_username);
        mEtSetUserPassword1 = findVIEwByID(R.ID.set_userPassword1);
        mEtSetUserPassword2 = findVIEwByID(R.ID.set_userPassword2);
        mBtToRegister = findVIEwByID(R.ID.bt_startRegister);

        dbHelper = new DBHelper(this);
        mBtToRegister.setonClickListener(this);
    }

    public voID onClick(VIEw vIEw){
        String username = mEtSetUsername.getText().toString().trim();
        String password1 = mEtSetUserPassword1.getText().toString().trim();
        String password2 = mEtSetUserPassword2.getText().toString().trim();

        if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password1)&& !TextUtils.isEmpty(password2)  ) {
                if ((password1.equals(password2))) {
                    if (dbHelper.add(username,password2)){
                        //将用户名和密码加入到数据库中
                        Intent intent2 = new Intent(this,LoginActivity.class);
                        startActivity(intent2);
                        finish();
                        ToastUtil.showMsg(Registeractivity.this,"注册成功!");
                    }
                    else {
                        ToastUtil.showMsg(Registeractivity.this,"该用户名已存在!");
                    }
                }
                else {
                    ToastUtil.showMsg(Registeractivity.this,"密码输入不一致");
                }
        }
        else {
            ToastUtil.showMsg(Registeractivity.this,"用户名和密码不能为空!");
        }
    }
}

EditinformationActivity

信息编辑activity

package com.example.myfirst;

import androIDx.appcompat.app.AppCompatActivity;

import androID.app.Activity;
import androID.content.Intent;
import androID.os.Bundle;
import androID.vIEw.VIEw;
import androID.Widget.button;
import androID.Widget.EditText;
import androID.Widget.Radiobutton;
import androID.Widget.RadioGroup;

import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.ToastUtil;
import com.example.myfirst.util.User;

import java.util.ArrayList;

public class EditinformationActivity extends AppCompatActivity implements VIEw.OnClickListener{

    private EditText mEtUsername,Metage,mEtFavorite,mEtSignature;
    private button mBtSaveinformation;
    private DBHelper dbHelper;
    private Radiobutton mRbMale,mRbFemale;
    private String sexString;

    @OverrIDe
    protected voID onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.activity_edit_infor);

        mEtUsername = findVIEwByID(R.ID.Et_EditUsername);
        Metage = findVIEwByID(R.ID.Et_editAge);
        mRbMale = findVIEwByID(R.ID.rdB_male);
        mRbFemale = findVIEwByID(R.ID.rdB_female);
        mEtFavorite = findVIEwByID(R.ID.Et_editFavorite);
        mEtSignature = findVIEwByID(R.ID.Et_editSignature);
        mBtSaveinformation = findVIEwByID(R.ID.bt_saveinformation);

        dbHelper = new DBHelper(this);

        showRadiobuttonIsCheck();

        mBtSaveinformation.setonClickListener(this);
    }

    private voID showRadiobuttonIsCheck(){            //定义一个根据用户性别显示 哪个radiobutton被选中的方法
        ArrayList<User> userData = dbHelper.getData();
        User user = userData.get(LoginActivity.getUserID());

        if (!(user.getSex() == null)){
            if (user.getSex().equals("男")){
                mRbMale.setChecked(true);
            }else if (user.getSex().equals("女")){
                mRbFemale.setChecked(true);
            }
        }
    }

    @OverrIDe
    public voID onClick(VIEw vIEw) {
        String username = mEtUsername.getText().toString().trim();
        String age = Metage.getText().toString();
        String favorite = mEtFavorite.getText().toString();
        String signature = mEtSignature.getText().toString();         //分别获取输入的用户信息

        if (!username.isEmpty()){
            dbHelper.updateUsername(username);
        }
        if (!age.isEmpty()){
            dbHelper.updateAge(age);
        }

        if (mRbMale.isChecked()){
            sexString = "男";
        }else if (mRbFemale.isChecked()){
            sexString = "女";
        }
        dbHelper.updateSex(sexString);

        if (!favorite.isEmpty()){
            dbHelper.updateFavorite(favorite);
        }
        if (!signature.isEmpty()){
            dbHelper.updateSignature(signature);        //分别保存到数据库中的User表,必须做一个是否为空的检查
        }                                               //否则表中数据可能会被覆盖

        SlIDeActivity.slIDeActivity.finish();              //更改后销毁原来的信息显示页面
        ToastUtil.showMsg(this,"更改成功");
        Intent intent = new Intent(EditinformationActivity.this,SlIDeActivity.class);
        startActivity(intent);
        finish();

    }
}

RelaxActivity

娱乐

package com.example.myfirst;

import androIDx.appcompat.app.AppCompatActivity;

import androID.content.Intent;
import androID.os.Bundle;
import androID.vIEw.VIEw;
import androID.Widget.button;

public class RelaxActivity extends AppCompatActivity {

    private button btnGame1,btnGame2,btnGame3,btnGame4,btnGame5,btnGame6,btnGame7,btnGame8,btnGame9;
    @OverrIDe
    protected voID onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.activity_relax);

        btnGame1 = findVIEwByID(R.ID.bt_game1);
        btnGame2 = findVIEwByID(R.ID.bt_game2);
        btnGame3 = findVIEwByID(R.ID.bt_game3);
        btnGame4 = findVIEwByID(R.ID.bt_game4);
        btnGame5 = findVIEwByID(R.ID.bt_game5);
        btnGame6 = findVIEwByID(R.ID.bt_game6);
        btnGame7 = findVIEwByID(R.ID.bt_game7);
        btnGame8 = findVIEwByID(R.ID.bt_game8);
        btnGame9 = findVIEwByID(R.ID.bt_game9);

        setClickListener();
    }
    private class OnClick implements VIEw.OnClickListener{      //新建私有类OnClick,实现VIEw.OnClickListener
        @OverrIDe                                               //重写onClick方法
        public voID onClick(VIEw vIEw) {
            Intent intent = null;
            switch (vIEw.getID()){
                case R.ID.bt_game1:
                    intent = new Intent(RelaxActivity.this,WebZTypeActivity.class);
                    break;
                case R.ID.bt_game2:
                    intent = new Intent(RelaxActivity.this,EatwhatActivity.class);
                    break;
                case R.ID.bt_game3:
                    intent = new Intent(RelaxActivity.this,SummondragonActivity.class);
                    break;
                case R.ID.bt_game4:
                    intent = new Intent(RelaxActivity.this,WhichoneActivity.class);
                    break;
                case R.ID.bt_game5:
                    intent = new Intent(RelaxActivity.this,MikutapActivity.class);
                    break;
                case R.ID.bt_game6:
                    intent = new Intent(RelaxActivity.this,HenxiangsiActivity.class);
                    break;
                case R.ID.bt_game7:
                    intent = new Intent(RelaxActivity.this,LoopTapActivity.class);
                    break;
                case R.ID.bt_game8:
                    intent = new Intent(RelaxActivity.this,FlowerActivity.class);
                    break;
                case R.ID.bt_game9:
                    intent = new Intent(RelaxActivity.this,EndlessLakeActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
    //设计方法
    private voID setClickListener(){
        OnClick onClick = new OnClick();       //在OnClick新建onClick实体,否则36行OnClick是灰色的,也就是没被调用
        btnGame1.setonClickListener(onClick); //每个button调用监听,并用上面的方法
        btnGame2.setonClickListener(onClick);
        btnGame3.setonClickListener(onClick);
        btnGame4.setonClickListener(onClick);
        btnGame5.setonClickListener(onClick);
        btnGame6.setonClickListener(onClick);
        btnGame7.setonClickListener(onClick);
        btnGame8.setonClickListener(onClick);
        btnGame9.setonClickListener(onClick);
    }
}

StudyActivity

学习

package com.example.myfirst;

import androIDx.appcompat.app.AppCompatActivity;

import androID.content.Intent;
import androID.os.Bundle;
import androID.vIEw.SearchEvent;
import androID.vIEw.VIEw;
import androID.Widget.button;

public class StudyActivity extends AppCompatActivity {

    private button btnStudy1,btnStudy2,btnStudy3,btnStudy4,btnStudy5,btnStudy6;

    @OverrIDe
    protected voID onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.activity_study);

        btnStudy1 = findVIEwByID(R.ID.btn_study1);
        btnStudy2 = findVIEwByID(R.ID.btn_study2);
        btnStudy3 = findVIEwByID(R.ID.btn_study3);
        btnStudy4 = findVIEwByID(R.ID.btn_study4);
        btnStudy5 = findVIEwByID(R.ID.btn_study5);
        btnStudy6 = findVIEwByID(R.ID.btn_study6);

        setClickListener();
    }

    private class OnClick implements VIEw.OnClickListener{     //新建私有类OnClick,与 VIEw.OnClickListener接口对接
        @OverrIDe
        public voID onClick(VIEw vIEw) {
            Intent intent = null;
            switch (vIEw.getID()){
                case R.ID.btn_study1:
                    intent = new Intent(StudyActivity.this,RunoobActivity.class);
                    break;
                case R.ID.btn_study2:
                    intent = new Intent(StudyActivity.this,TechnologyMuseumActivity.class);
                    break;
                case R.ID.btn_study3:
                    intent = new Intent(StudyActivity.this,MedicineActivity.class);
                    break;
                case R.ID.btn_study4:
                    intent = new Intent(StudyActivity.this,AnswerActivity.class);
                    break;
                case R.ID.btn_study5:
                    intent = new Intent(StudyActivity.this,SpaceActivity.class);
                    break;
                case R.ID.btn_study6:
                    intent = new Intent(StudyActivity.this,DeepSeaActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
    private voID setClickListener(){
        OnClick onClick = new OnClick();
        btnStudy1.setonClickListener(onClick);
        btnStudy2.setonClickListener(onClick);
        btnStudy3.setonClickListener(onClick);
        btnStudy4.setonClickListener(onClick);
        btnStudy5.setonClickListener(onClick);
        btnStudy6.setonClickListener(onClick);          //每个button调用监听,并用上面的方法
    }
}

SlIDeActivity

侧滑

package com.example.myfirst;

import androIDx.appcompat.app.AppCompatActivity;

import androID.app.Activity;
import androID.content.Intent;
import androID.os.Bundle;
import androID.vIEw.VIEw;
import androID.Widget.button;
import androID.Widget.ImageVIEw;
import androID.Widget.TextVIEw;

import com.example.myfirst.util.DBHelper;
import com.example.myfirst.util.SlIDeMenu;
import com.example.myfirst.util.User;

import java.util.ArrayList;

public class SlIDeActivity extends AppCompatActivity {

    private ImageVIEw mIvhead;
    private SlIDeMenu slIDeMenu;
    private button buttonStudy;
    private button buttonRelax;
    private button buttonToEdit;
    private TextVIEw mTvUsername,mTvSex,mTvAge,mTvFavorite,mTvSignature;
    private DBHelper dbHelper;

    public static SlIDeActivity slIDeActivity;

    @OverrIDe
    protected voID onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.activity_slIDe);
        slIDeActivity = this;

        mIvhead = findVIEwByID(R.ID.iv_head);
        slIDeMenu = findVIEwByID(R.ID.slIDeMenu);
        buttonStudy = findVIEwByID(R.ID.btn_study);
        buttonRelax = findVIEwByID(R.ID.btn_relax);
        buttonToEdit = findVIEwByID(R.ID.bt_toEdit);

        mTvUsername = findVIEwByID(R.ID.tv_username);               //用户信息显示控件
        mTvSex = findVIEwByID(R.ID.tv_userSex);
        mTvAge = findVIEwByID(R.ID.tv_userAge);
        mTvFavorite = findVIEwByID(R.ID.tv_userFavorite);
        mTvSignature = findVIEwByID(R.ID.tv_userSignature);

        mIvhead.setonClickListener(v -> slIDeMenu.switchMenu());

        setClickListener();

        dbHelper = new DBHelper(this);
        showUserinformation();
    }
//由于button太多,设计一个方法,设计方法之前写好要调用的类
    private class OnClick implements VIEw.OnClickListener{      //新建私有类OnClick,实现VIEw.OnClickListener
        @OverrIDe                                               //重写onClick方法
        public voID onClick(VIEw vIEw) {
            Intent intent = null;
            switch (vIEw.getID()){
                case R.ID.btn_study:
                    intent = new Intent(SlIDeActivity.this,StudyActivity.class);
                    break;
                case R.ID.btn_relax:
                    intent = new Intent(SlIDeActivity.this,RelaxActivity.class);
                    break;
                case R.ID.bt_toEdit:
                    intent = new Intent(SlIDeActivity.this,EditinformationActivity.class);
            }
            startActivity(intent);
        }
    }
//设计方法
    private voID setClickListener(){
        OnClick onClick = new OnClick();         //在OnClick新建onClick实体,否则36行OnClick是灰色的,也就是没被调用
        buttonStudy.setonClickListener(onClick); //每个button调用监听,并用上面的方法
        buttonRelax.setonClickListener(onClick);
        buttonToEdit.setonClickListener(onClick);
    }

    private voID showUserinformation() {                          //建立获取用户信息的方法
        ArrayList<User> userData2 = dbHelper.getData();           //创建User队列 userData2
        User user = userData2.get(LoginActivity.getUserID());      //创建一个实体user,并获取当前用户ID的数据
        mTvUsername.setText(user.getname());
        mTvAge.setText(user.getAge());
        mTvSex.setText(user.getSex());
        mTvFavorite.setText(user.getFavorite());                  //分别获取用户信息到TV控件
        mTvSignature.setText(user.getSignature());
    }
}

实现侧滑功能

这里使用了别人封装好的类,

支付解锁全部内容

限时5折
¥9.9 ¥19.9

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

HTML相关文章

HTML邮件内容所在上下文或者说所在外部容器(以下简...
HTML内容类型决定使用的语义标签,在网页中某种类型...
HTML代码在书写的时候应该遵循什么规范?青岛星网今...