zoukankan      html  css  js  c++  java
  • android登录功能

    界面

    activity_login.xml文件:

      1 <?xml version="1.0" encoding="utf-8"?>
      2 <!--
      3 这里把整个Activity_login的布局设置成相对布局,
      4 因为相对布局比较灵活,想咋放咋放
      5 看代码,上来就是三个 xmlns,xml这仨字母认识,ns这俩字母是namespace的缩写
      6 正是有了这些namespace的声明,才能在不同的xml中使用相同的id名,
      7 而不会造成使用时的冲突
      8 -->
      9 <RelativeLayout
     10     xmlns:android="http://schemas.android.com/apk/res/android"
     11     xmlns:app="http://schemas.android.com/apk/res-auto"
     12     xmlns:tools="http://schemas.android.com/tools"
     13     android:layout_width="match_parent"
     14     android:layout_height="match_parent"
     15     android:background="#eeeeee"
     16     tools:context=".loginActivity">
     17 <!--
     18 整体是相对布局,
     19 在整体上方放三个东西,这三个东西也是相对布局
     20 合在一起称为一个top
     21 一个返回箭头   ←
     22 两个文字显示   登录  注册
     23 也就是说   login界面的上方长这个样子
     24       ←   登录       注册
     25 下面是具体代码
     26 -->
     27     <RelativeLayout
     28         android:id="@+id/rl_loginactivity_top"
     29         android:layout_width="match_parent"
     30         android:layout_height="70dp"
     31         android:background="@color/color_minefragment_top" >
     32     <ImageView
     33         android:id="@+id/iv_loginactivity_back"
     34         android:layout_width="30dp"
     35         android:layout_height="30dp"
     36         android:background="@drawable/ic_left_back"
     37         android:layout_centerVertical="true"
     38         android:layout_marginLeft="10dp"
     39         android:clickable="true"
     40         android:onClick="onClick"
     41         />
     42 
     43     <TextView
     44         android:id="@+id/tv_loginactivity_login"
     45         android:layout_width="wrap_content"
     46         android:layout_height="wrap_content"
     47         android:text="登录"
     48         android:textColor="#fff"
     49         android:textSize="20dp"
     50         android:layout_toRightOf="@+id/iv_loginactivity_back"
     51         android:layout_centerVertical="true"
     52         android:layout_marginLeft="20dp"
     53         />
     54     <TextView
     55         android:id="@+id/tv_loginactivity_register"
     56         android:layout_width="wrap_content"
     57         android:layout_height="wrap_content"
     58         android:text="注册"
     59         android:textColor="#fff"
     60         android:textSize="20dp"
     61         android:layout_centerVertical="true"
     62         android:layout_alignParentRight="true"
     63         android:layout_marginRight="30dp"
     64         android:clickable="true"
     65         android:onClick="onClick"
     66         />
     67     </RelativeLayout>
     68 <!--
     69  顶部三个东西摆放好之后
     70  就该来摆放登录时候的两个文本输入框了
     71  用户名
     72  密码
     73  这个明显的是LinerLayout
     74  LinerLayout必须指明orientation 方向 要么垂直vertical 要么水平 horizontal
     75  这里显然是垂直vertical
     76  -->
     77     <LinearLayout
     78         android:id="@+id/ll_loginactivity_two"
     79         android:layout_width="match_parent"
     80         android:layout_height="wrap_content"
     81         android:orientation="vertical"
     82         android:layout_below="@+id/rl_loginactivity_top"
     83         android:layout_marginTop="10dp"
     84         android:layout_marginLeft="5dp"
     85         android:layout_marginRight="5dp"
     86         >
     87         <LinearLayout
     88             android:layout_width="match_parent"
     89             android:layout_height="wrap_content"
     90             android:orientation="horizontal">
     91             <TextView
     92                 android:id="@+id/tv_loginactivity_username"
     93                 android:layout_width="wrap_content"
     94                 android:layout_height="wrap_content"
     95                 android:text="用户名:"/>
     96             <EditText
     97                 android:id="@+id/et_loginactivity_username"
     98                 android:layout_width="match_parent"
     99                 android:layout_height="wrap_content"
    100                 android:hint="手机号/邮箱/用户名"/>
    101         </LinearLayout>
    102         <LinearLayout
    103             android:layout_width="match_parent"
    104             android:layout_height="wrap_content"
    105             android:orientation="horizontal">
    106             <TextView
    107                 android:id="@+id/tv_loginactivity_password"
    108                 android:layout_width="wrap_content"
    109                 android:layout_height="wrap_content"
    110                 android:text="密    码:"/>
    111             <EditText
    112                 android:id="@+id/et_loginactivity_password"
    113                 android:layout_width="match_parent"
    114                 android:layout_height="wrap_content"
    115                 android:hint="登录密码"
    116                 android:inputType="textPassword"/>
    117         </LinearLayout>
    118     </LinearLayout>
    119 <!--
    120   填好用户名、密码后,就该点击登录按钮了
    121   注意最后有一句: android:onClick="onClick"
    122   这是应用了一个开源库,详细信息在loginActivity.java 中有注释
    123   -->
    124     <Button
    125         android:id="@+id/bt_loginactivity_login"
    126         android:layout_width="match_parent"
    127         android:layout_height="wrap_content"
    128         android:layout_below="@+id/ll_loginactivity_two"
    129         android:layout_marginTop="10dp"
    130         android:layout_marginLeft="5dp"
    131         android:layout_marginRight="5dp"
    132         android:background="@drawable/selector_loginactivity_button"
    133         android:text="登录"
    134         android:textColor="#fff"
    135         android:gravity="center"
    136         android:onClick="onClick"
    137         />
    138 <!--
    139     为了App的人性化,
    140     想到有以下三种无法密码登录的异常处理情况
    141     一、密码错误,重新输入
    142     二、忘记密码,重新修改密码
    143     三、不想注册,通过短信验证登录
    144     密码输错了,重新输入,这个没啥说的
    145     忘记密码应该以一个可以点击的文字出现在登录按钮的左下方
    146     短信验证登录也以一个可以点击的文字出现在登录按钮的右下方
    147 -->
    148     <TextView
    149         android:id="@+id/tv_loginactivity_forget"
    150         android:text="忘记密码"
    151         android:textColor="#f00"
    152         android:layout_width="wrap_content"
    153         android:layout_height="wrap_content"
    154         android:layout_marginLeft="50dp"
    155         android:layout_marginVertical="50dp"
    156         android:layout_below="@+id/bt_loginactivity_login"
    157         android:layout_alignLeft="@+id/bt_loginactivity_login"
    158         />
    159     <TextView
    160         android:id="@+id/tv_loginactivity_check"
    161         android:layout_width="wrap_content"
    162         android:layout_height="wrap_content"
    163         android:text="短信验证码登录"
    164         android:textColor="#f00"
    165         android:layout_marginRight="50dp"
    166         android:layout_marginVertical="50dp"
    167         android:layout_below="@+id/bt_loginactivity_login"
    168         android:layout_alignRight="@+id/bt_loginactivity_login"
    169         />
    170 <!--
    171 当然,QQ、微信、微博、GitHub...在当今如此火热
    172 登录的时候完全可以免注册
    173 直接使用第三方登录
    174   -->
    175     <TextView
    176         android:id="@+id/tv_loginactivity_else"
    177         android:layout_width="wrap_content"
    178         android:layout_height="wrap_content"
    179         android:layout_below="@+id/tv_loginactivity_forget"
    180         android:layout_centerInParent="true"
    181         android:layout_marginVertical="30dp"
    182 
    183         android:text="---------------------------第三方登录---------------------------"
    184         android:textColor="#B3B3B3"
    185         android:gravity="center"
    186         />
    187 </RelativeLayout>

    界面效果:

  • 相关阅读:
    mysql8.0 一次性备份导出/导入恢复所有数据库
    访问服务器共享资源不需要输帐号和密码
    win7 系统 提示用户'sa'登录失败
    Adoquery.disablecontrols和enablecontrols
    DBGridEh 导出数据到EXCEL文件
    Microsoft SQL Server 2005资料库(数据库)卸载方法
    64位操作系统下创建组件失败的解决办法
    U盘中的文件为什么看不见?
    解决错误提示unable to invoke code completion due to errors in source cord.
    浪潮服务器Windows Server系统异常断电导致系统中CentOS7虚拟机系统崩溃无法正常启动grub2故障修复error: relocation 0x48 is not implemented yet
  • 原文地址:https://www.cnblogs.com/znjy/p/14884203.html
Copyright © 2011-2022 走看看