Android开发中实现用户注册和登陆的小demo分享

本文实例讲述了Android实现登录功能的方法。分享给大家供大家参考,具体如下:

登陆效果: 应用程序判断当前用户还未登陆,弹出登陆对话框,用户输入账号和密码信息后,传到服务器验证,验证成功后,现实Toast 成功信息,并转到其他界面。

2015121161004202.jpg (480×800)

注册效果:用户如没有账号,则点击登陆对话框的 “没有账号,快速注册账号”, 弹出注册界面,用户输入注册信息,点击注册按钮,注册成功后,弹出toast信息”注册成功”,完成注册后,转到其他功能界面。

2015121161036365.jpg (480×800)

整个功能大体上分两块:登陆对话框:输入登陆信息,实现登陆功能,转到注册界面。注册对话框:输入注册信息,实现注册功能。

对话框界面布局xml文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout
   android:layout_width = "fill_parent"
   android:layout_height = "wrap_content"
   android:orientation = "vertical" >
   
   < TextView
    android:id = "@+id/txt_loginerror"
    android:layout_height = "wrap_content"
    android:layout_width = "wrap_content"
    android:layout_marginLeft = "20dip"
    android:layout_marginRight = "20dip"
    android:textColor = "#ff0000"
    android:text = "输入的账号和密码不正确"
    android:gravity = "left"
    android:textAppearance = "?android:attr/textAppearanceMedium"
    android:visibility = "invisible"
   />
   
   
   < TextView
    android:id = "@+id/username"
    android:layout_height = "wrap_content"
    android:layout_width = "wrap_content"
    android:layout_marginLeft = "20dip"
    android:layout_marginRight = "20dip"
    android:text = "账号"
    android:gravity = "left"
    android:textAppearance = "?android:attr/textAppearanceMedium"
   />
    
   < EditText
    android:id = "@+id/txt_username"
    android:layout_height = "wrap_content"
    android:layout_width = "fill_parent"
    android:layout_marginLeft = "20dip"
    android:layout_marginRight = "20dip"
    android:autoText = "false"
    android:capitalize = "none"
    android:gravity = "fill_horizontal"
    android:textAppearance = "?android:attr/textAppearanceMedium"
    />
   < TextView
    android:id = "@+id/password"
    android:layout_height = "wrap_content"
    android:layout_width = "wrap_content"
    android:layout_marginLeft = "20dip"
    android:layout_marginRight = "20dip"
    android:textAppearance = "?android:attr/textAppearanceMedium"
    android:text = "密码"
    android:gravity = "left"
    />
   < EditText
    android:id = "@+id/txt_password"
    android:layout_height = "wrap_content"
    android:layout_width = "fill_parent"
    android:layout_marginLeft = "20dip"
    android:layout_marginRight = "20dip"
    android:autoText = "false"
    android:capitalize = "none"
    android:gravity
  • 0
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值