Android——实现登录和注册功能

前言

自学Android有段时间了,觉得是时候尝试写一些小demo尝试一下。这次尝试写了一个登录注册功能,大概涉及以下几个知识点:使用LitePal操作数据库、颜色渐变、嵌套布局。其他的皆是比较正常的知识。话不多说,进入正题。

正文

UI界面

登录

先来说说登录界面的实现。
在布局上最外层我使用了LinearLayout,这也是我在布局中使用最多也是最熟悉的布局,所以我首选这个,比较方便,里面我嵌套了两个LinearLayout和一个RelativeLayout。算是比较简单吧,也是经过我多次尝试之后选出的最佳方案。上面有的东西就是平常大家常见的功能,头像显示,记住密码忘记密码这些东西,我还特意加了三个其他登陆方式,当然这个没有实现,知识UI上有而已,不过后续完善的时候可以实现。同样的记住密码和忘记密码功能我也没来得及实现。最近比较忙,还要上其他课。话不多说给大家放出登陆界面代码。可结合效果图进行参考。

<?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/background_gradient">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

    <ImageView
        android:id="@+id/lg_userIcon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:scaleType="fitCenter"
        android:src="@drawable/headportrait"/>

    <EditText
        android:id="@+id/lg_username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/lg_userIcon"
        android:layout_marginTop="30dp"
        android:drawableLeft="@drawable/user"
        android:theme="@style/myedittext_color"
        android:drawablePadding="5dp"
        android:hint="账号"
        android:maxLines="1"/>

    <EditText
        android:id="@+id/lg_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/lg_username"
        android:layout_marginTop="10dp"
        android:theme="@style/myedittext_color"
        android:drawableLeft="@drawable/psd"
        android:drawablePadding="5dp"
        android:hint="密码"
        android:maxLines="1"
        android:inputType="textPassword"/>

    <LinearLayout
        android:id="@+id/ly"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/lg_password">

        <CheckBox
            android:id="@+id/lg_rememberPsd"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="5"
            android:text="记住密码"
            android:theme="@style/cb_color"
            android:textColor="#1E90FF"/>

        <TextView
            android:id="@+id/lg_forgetPsd"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="忘记密码"
            android:textColor="#1E90FF"/>

    </LinearLayout>

    <Button
        android:id="@+id/lg_login"
        android:layout_width="match_parent"
        android:layout_height
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值