继启动界面之后,现在开始做登录界面和注册界面。需要看启动界面教学的,请戳我的博客:
Android Studio之启动界面教学
Android Studio之启动界面教学.
Android Studio之备忘录教学
Android Studio之备忘录教学.
其实安卓的登录注册,和JAVA是一样的,甚至于是极简版的JAVA登录注册,安卓太智能了,数据保存在sqllite中,完全不需要导包,而且还伴有可视化界面,简直无敌,安卓可以说是目前我们学过的最简单的语言,只是大家没有好好学罢了。如果大家认真学习,会发现真的超简单…
闲话不多说,接下来直接开始。
首先,先创建登录和注册两个activity,我这里取名为LoginActivity和RegisterActivity,我们取名要尽量做到规范,要让别人一眼就能看出来你这个是什么,不要总是取什么“aa”,“bb”,"cc"这种名字,让别人给你改代码看的都烦,估计你自己过一段时间都不知道你这文件是什么了,对吧?
创建两个activity,创建好了之后是这样的:
然后,我们再创建两个java.class文件,注意,不是创建activity。命名为User和DBOpenHelper,User就相当于我们java中的用户类,DBOpenHelper就相当于java中的DBUtils工具类,非常简单是不是?
接下来,我们先打开activity_login.xml,开始制作登录界面。 登录界面,我整体是相对布局, 在整体上方放三个东西,这三个东西也是相对布局合在一起称为一个top,下面是具体代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="#eeeeee"
tools:context=".LoginActivity">
<RelativeLayout
android:id="@+id/rl_loginactivity_top"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@color/color_minefragment_top" >
<ImageView
android:id="@+id/iv_loginactivity_back"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/ic_left_back"
android:clickable="true"
android:onClick="onClick" />
<TextView
android:id="@+id/tv_loginactivity_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"
android:textColor="#fff"
android:textSize="20dp"
android:layout_toRightOf="@+id/iv_loginactivity_back"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
/>
<TextView
android:id="@+id/tv_loginactivity_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textColor="#fff"
android:textSize="20dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:clickable="true"
android:onClick="onClick"
/>
</RelativeLayout>
顶部三个东西摆放好之后就该来摆放登录时候的两个文本输入框了用户名密码 这个明显的是LinerLayout,LinerLayout必须指明orientation 方向 要么垂直vertical 要么水平 horizontal,这里显然是垂直vertical.
<LinearLayout
android:id="@+id/ll_loginactivity_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/rl_loginactivity_top"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_loginactivity_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"/>
<EditText
android:id="@+id/et_loginactivity_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="手机号/邮箱/