Android实现登录界面的注册功能
作者:DY.memory 发布时间:2021-10-22 01:17:55
标签:Android,登录,注册
本文实例为大家分享了Android登录界面的注册实现代码,供大家参考,具体内容如下
注册一个登录界面在控制台将输入的信息文本选框展示出来
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"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"
android:textSize="35sp"
android:gravity="center"
android:background="#FF5722"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="210dp"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/qq"
android:layout_weight="1"
android:text="用QQ注册"
android:gravity="center"
android:textSize="20sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="210dp"
android:background="@drawable/wechat"
android:layout_weight="1"
android:text="用微信注册"
android:textSize="20sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/yxlg"
android:layout_marginTop="12dp"
android:layout_marginLeft="80dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/net"
/>
<TextView
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:id="@+id/yxld"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" 用邮箱登录"
android:gravity="center"
android:textSize="35sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:paddingTop="12dp"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="名字:"
android:gravity="left"
android:textSize="25sp"
/>
<EditText
android:id="@+id/mz"
android:paddingTop="12dp"
android:background="@null"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:paddingTop="12dp"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="账号:"
android:gravity="left"
android:textSize="25sp"
/>
<EditText
android:id="@+id/zh"
android:paddingTop="12dp"
android:background="@null"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:paddingTop="12dp"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="密码:"
android:gravity="left"
android:textSize="25sp"
/>
<EditText
android:password="true"
android:id="@+id/mm"
android:paddingTop="12dp"
android:background="@null"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:paddingTop="12dp"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="性别: "
android:gravity="left"
android:textSize="25sp"
/>
<RadioGroup
android:id="@+id/xb"
android:layout_marginTop="15dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/nan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:textSize="20sp"
/>
<RadioButton
android:id="@+id/nu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
android:textSize="20sp"
/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:paddingTop="12dp"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="选择你的爱好:"
android:gravity="left"
android:textSize="25sp"
/>
<CheckBox
android:id="@+id/cg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="唱歌"
android:textSize="20sp" />
<CheckBox
android:id="@+id/tw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="跳舞"
android:textSize="20sp" />
<CheckBox
android:id="@+id/ds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="读书"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorAccent"
>
</LinearLayout>
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="提交"
android:textSize="30sp"
/>
</LinearLayout>
注册功能实现
package com.example.registerlogin;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{
private EditText mz,zh,mm;
private Button btn1;
private String name,id,pwd,sex,hobby;
private RadioGroup xb;
private CheckBox cg,tw,ds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=findViewById(R.id.btn1);
mz=findViewById(R.id.mz);
zh=findViewById(R.id.mz);
mm=findViewById(R.id.mz);
cg=findViewById(R.id.cg);
tw=findViewById(R.id.tw);
ds=findViewById(R.id.ds);
xb=findViewById(R.id.xb);
btn1.setOnClickListener(MainActivity.this);
xb.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
{switch (checkedId){
case R.id.nan:
sex = "男";
break;
case R.id.nu:
sex="女";
break;
}
}
}
});
}
private void getData(){
name=mz.getText().toString().trim();
id=zh.getText().toString().trim();
pwd=mm.getText().toString().trim();
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn1:
getData();
if (TextUtils.isEmpty(name)) {
Toast.makeText(MainActivity.this, "请输入名字", Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(id)) {
Toast.makeText(MainActivity.this, "请输入账号", Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(pwd)) {
Toast.makeText(MainActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(sex)) {
Toast.makeText(MainActivity.this, "请输入性别", Toast.LENGTH_SHORT).show();
}else if (TextUtils.isEmpty(hobby)) {
Toast.makeText(MainActivity.this, "请输入爱好", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this, "注册成功", Log.i("MainActivity", "检测到你的注册信息:" + "名字:" + name + " 邮箱:" + id + " 性别:" + sex+" 爱好:"+hobby));
}
break;
}
}
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
String motion =buttonView.getText().toString();
if(isChecked){
if(!hobby.contains(motion)){
hobby = hobby + motion;
}
}else {
if(hobby.contains(motion)){
hobby=hobby.replace(motion,"");
}
}
}
}
我没有输入爱好,所以控制台输出null
这个代码较简单,xml用到的都是一些简单的线性布局,和一些对控件位置和id的改动,定义,Java文件用的是对xml控件的获取和输出,展示!
来源:https://blog.csdn.net/Abtxr/article/details/123751677


猜你喜欢
- Java 序列化和反序列化实例详解在分布式应用中,对象只有经过序列化才能在各个分布式组件之间传输,这就涉及到两个方面的技术-发送者将对象序列
- 本文实例讲述了安卓Android6.0权限动态获取操作。分享给大家供大家参考,具体如下:众所周知 , 安卓6.0现在运用的越来越广泛 , 因
- 《IDEA 破解新招 - 无限重置30天试用期》,这种方法适用idea2021以下所有版本,亲测idea2020.3成功激活,其他版本自测吧
- 一、背景很多 Java 工程师在准备面试时,会刷很多八股文,线程和线程池这一块通常会准备线程的状态、线程的创建方式,Executors 里面
- 效果视频引用描述本示例采用的是非常、非常、非常好用的一款第三方SDK——helloCharts传送门导包第一步 :导入mavenmaven
- 本文实例为大家分享了java实现双色球抽奖的具体代码,供大家参考,具体内容如下实现双色球先考虑整体思路:1.随机生成7位数的数组为大奖号码(
- 先利用jsoup将得到的html代码“标准化”(Jsoup.parse(String html))方法,然后利用FileWiter将此htm
- 发现问题最近在进行压测发现,有一些接口时好时坏,通过sentry日志平台及sky walking平台跟踪发现,用户张三获取到的用户上下文确是
- 一、简介应用程序配置文件(App.config)是标准的 XML 文件,XML 标记和属性是区分大小写的。它是可以按需要更改的,开发人员可以
- 关于UIToolbarToolBar工具栏是视图View的属性,可以在工具栏上添加工具栏按钮Bar Button Item(可以是自定义的C
- 本文主要研究的是关于Java中重载,重写,多态,静态绑定、动态绑定的相关内容,具体如下。重载,英文名是overload,是指在一个类中定义了
- 一、什么是IOC1)控制反转,把创建对象和对象的调用过程交给Spring 管理。2)使用IOC的目的,为了降低耦合度。二、IOC的底层原理X
- Android异常详情介绍这种异常我遇到以下两种情况: 1. java.lang.IllegalStateException: No wra
- 前言延迟初始化 是一种将对象的创建延迟到第一次需要用时的技术,换句话说,对象的初始化是发生在真正需要的时候才执行,值得注意的是,术语&nbs
- 前言我身边有一部分开发的小伙伴,存在着这样一种习惯。某一天,突然看到某一款 App 上有个很漂亮的自定义控件(动画)效果,就会绞尽脑子想办法
- XML中的扫描过程<?xml version="1.0" encoding="utf-8" ?
- 本文实例讲述了C#字符串加密解密方法。分享给大家供大家参考。具体如下:#region 加密解密static string encryptKe
- 简介上一篇我们介绍了在android里如何读写本地文件。我们有一种场景,类似网页的cookie,要把用户的一些储如上一次登录、使用的痕迹等信
- 概述还没玩过Spring Boot,现在越来越多的公司在用了,不得不学习了。本篇是Spring Boot的开篇,简单介绍一下如何创建一个Sp
- //有何不足或者问题希望能够得到各位的多多指正,不胜感激import java.util.Scanner;/** *