论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
朋友圈
看朋友圈动态,了解ToB世界。
ToB门户
了解全球最新的ToB事件
博客
Blog
排行榜
Ranklist
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
导读
Guide
相册
Album
记录
Doing
应用中心
搜索
本版
文章
帖子
ToB圈子
用户
免费入驻
产品入驻
解决方案入驻
公司入驻
案例入驻
登录
·
注册
账号登录
立即注册
找回密码
用户名
Email
自动登录
找回密码
密码
登录
立即注册
首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
圈子
SAAS
qidao123.com技术社区-IT企服评测·应用市场
»
论坛
›
软件与程序人生
›
移动端开发
›
Android开发--实现Android登录注册页面(上) ...
Android开发--实现Android登录注册页面(上)
前进之路
论坛元老
|
2022-6-25 00:35:58
|
显示全部楼层
|
阅读模式
楼主
主题
1637
|
帖子
1637
|
积分
4911
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要
登录
才可以下载或查看,没有账号?
立即注册
x
简单的Android开发登录注册,这个是没有连数据库的
首先,新建项目,新建一个登录页面LoginActivity和注册页面RegisterActivity。
下面是登录页面的代码:activity_login.xml
<?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=".LoginActivity">
<LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:gravity="center_vertical">
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><TextView
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:text="账号:"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:textSize="25sp" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><EditText
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:id="@+id/et_account"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:hint="请输入用户名或手机号"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> style="@style/MyEditStyle"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_marginLeft="10dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:inputType="text"></EditText>
</LinearLayout>
<LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:gravity="center_vertical">
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><TextView
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:text="密码:"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:textSize="25sp" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><EditText
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:id="@+id/et_password"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:hint="请输入密码"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> style="@style/MyEditStyle"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_marginLeft="10dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:inputType="numberPassword"></EditText>
</LinearLayout>
<LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:gravity="center"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>>
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><CheckBox
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:id="@+id/cb_remember"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:text="记住密码"></CheckBox>
</LinearLayout>
<Button
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:id="@+id/btn_login"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:text="登录"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>style="@style/MyBtnStyle"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"></Button>
<TextView
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:textColor="@color/colorPrimary"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:text="还没有账号?"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_gravity="right"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="10dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:onClick="toRegister"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>></TextView>
</LinearLayout>
复制代码
效果如图:
下面是注册页面的代码:activity_register.xml
<?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=".LoginActivity">
<LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:gravity="center_vertical">
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><TextView
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:text="账号:"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:textSize="25sp" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><EditText
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:id="@+id/et_account"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:hint="请输入用户名或手机号"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> style="@style/MyEditStyle"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_marginLeft="10dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:inputType="text"></EditText>
</LinearLayout>
<LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:gravity="center_vertical">
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><TextView
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:text="密码:"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:textSize="25sp" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><EditText
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:id="@+id/et_password"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:hint="请输入密码"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> style="@style/MyEditStyle"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_marginLeft="10dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:inputType="numberPassword"></EditText>
</LinearLayout>
<LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:orientation="horizontal"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:gravity="center"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>>
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources><CheckBox
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:id="@+id/cb_remember"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources> android:text="记住密码"></CheckBox>
</LinearLayout>
<Button
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:id="@+id/btn_login"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:text="登录"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>style="@style/MyBtnStyle"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginLeft="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"></Button>
<TextView
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:textColor="@color/colorPrimary"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:text="还没有账号?"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_gravity="right"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginRight="20dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:layout_marginTop="10dp"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>android:onClick="toRegister"
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>></TextView>
</LinearLayout><?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
复制代码
效果如图:
最后,在LoginActivity.java中,加入一串代码:getSupportActionBar().setTitle("登录");
在RegisterActivity.java中,加入一串代码:getSupportActionBar().setTitle("注册");
public class LoginActivity extends AppCompatActivity {
public static final int REQUEST_CODE_REGISTER = 1;
private static final String TAG="tag";
private Button btnLogin;
private EditText etAccount,etPassword;
private CheckBox cbRemember;
private String userName="a";
private String pass="123";
@Override
protected void onCreate(Bundle savedInstanceState) {
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>super.onCreate(savedInstanceState);
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>setContentView(R.layout.activity_login);
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>getSupportActionBar().setTitle("登录");
}
}
复制代码
上面的代码是LoginActivity.java中的代码,其实要添加的只有一句,其他都写出来是为了让读者能看懂,具体写在哪里。这段代码的作用是: 使标题栏那边显示的文字是登录/注册,而不是一串默认的英文
下面两张图片,左边是未添加代码的效果,右边是添加代码后的效果
写到这里,页面整体布局大致完成了,下面,你们需要添加部分细节,来使得颜色和样式跟我一致。我在上面的xml文件代码中,有下面这个代码:
style="@style/MyEditStyle"和style="@style/MyBtnStyle"
复制代码
你们在前面写的时候,可能会报错,很正常,因为这是引用控件样式的代码,你们需要设置一下这个样式,然后引用,就不会报错啦。
这是设置EditText和Button控件的样式,首先新建style.xml文件。在values中右键,New--Values Resource File,文件名为style。在style.xml文件中,写如下代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
复制代码
这里面又引用了样式,是设置输入框的边框和按钮的背景颜色。继续下面的步骤:drawable右键--New--Drawable Resource File,文件名为:btn_bg_selector,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
复制代码
drawable右键--New--Drawable Resource File,文件名为:edit_text_bg,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
复制代码
最后,再调整一下导航栏和标题栏的颜色,就OK啦
colors.xml文件中,添加绿色这个颜色,如下代码,
<color name="colorPrimary">@color/green_500</color>
<color name="colorPrimaryDark">@color/green_700</color>
<color name="colorAccent">#E64A19</color>
<color name="green_200">#A5D6A7</color>
<color name="green_500">#4CAF50</color>
<color name="green_700">#4CAF50</color>
复制代码
themes.xml文件中,只需要修改前两个item的内容,其他代码是为了你们参照一下位置,别改错了。代码如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
复制代码
到这里,你的登录注册页面部分就完成啦!恭喜你!
以上代码,都是我自己一个个敲的,也运行过,运行结果是没问题的。当然如果你有什么意见建议,请不吝赐教❥(^_-)
具体的跳转实现看下一篇笔记哦,下一篇笔记结尾也有源码分享。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复
使用道具
举报
0 个回复
倒序浏览
返回列表
快速回复
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
or
立即注册
本版积分规则
发表回复
回帖并转播
回帖后跳转到最后一页
发新帖
回复
前进之路
论坛元老
这个人很懒什么都没写!
楼主热帖
后台性能测试规范
UWP/WinUI3 Win2D PixelShaderEffec ...
低代码平台 - 危险的赌注
小小项目-博客系统 - 服务器版本 - jav ...
端午假期整理了仿天猫H5 APP项目vue.js ...
Docker 基础 - 1
Python3程序捕获Ctrl+C终止信号 ...
实用五步法教会你指标体系的设计与加工 ...
Redis常见使用场景
Fastjson反序列化
标签云
渠道
国产数据库
集成商
AI
运维
CIO
存储
服务器
浏览过的版块
linux
快速回复
返回顶部
返回列表