Android:注册界面

前端界面(布局文件) :ScrollView(滚动视图布局)+TextView(设置跑马灯)+EditText(编辑框)+TextView(文本框)+RadioGroup(单选按钮组)+Spinner(下拉列表)+CheckBox(多选框)+RatingBar(评分条)
java代码:setOnFocusChangeListener(EditText离开编辑框时监听事件)+setOnClickListener(一般的按钮监听事件)+setOnCheckedChangeListener(单选按钮监听事件)+setOnItemSelectedListener(多选框选中监听事件)+setOnRatingBarChangeListener(单击评分条监听事件)

布局文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="left"android:paddingLeft="20dp"android:text="返回"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:paddingLeft="120dp"android:text="用户登录"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:paddingLeft="130dp"android:text="注册"/></LinearLayout><TextViewandroid:padding="10dp"android:background="#ff00ff00"android:layout_centerInParent="true"android:layout_width="match_parent"android:layout_height="wrap_content"android:singleLine="true"android:ellipsize="marquee"android:focusable="true"android:focusableInTouchMode="true"android:marqueeRepeatLimit="marquee_forever"android:text="加油,未来可期!加油,你是最棒的!加油,享受当下时光!加油加油加油加油加油加油" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="用户名:"android:textSize="20sp"/><EditTextandroid:id="@+id/edtUserName"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="2"android:hint="请输入用户名"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="密码:"android:textSize="20sp"/><EditTextandroid:id="@+id/edtPassWd"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="2"android:hint="请输入密码6-12位"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="确认密码:"android:textSize="20sp"/><EditTextandroid:id="@+id/edtConfirmPassWd"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="2"android:hint="请确认输入密码6-12位"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><RadioGroupandroid:id="@+id/rdgGender"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="性别:"android:textSize="20sp"/><RadioButtonandroid:id="@+id/rdMale"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:textSize="20sp"android:text="男"/><RadioButtonandroid:id="@+id/rdFeMale"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:textSize="20sp"android:text=" 女"/></RadioGroup></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:layout_width="0dp"android:layout_weight="2"android:layout_height="wrap_content"android:text="出生地:"android:textSize="20sp"/><Spinnerandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/s_main_spinner1"></Spinner><Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/s_main_spinner2" > </Spinner></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_height="wrap_content"android:layout_width="wrap_content"android:textSize="20sp"android:text="@string/title" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:orientation="horizontal"><CheckBoxandroid:id="@+id/checkbox1"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:textSize="16sp"android:text="@string/reading"/><CheckBoxandroid:id="@+id/checkbox2"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:text="@string/coding"/><CheckBoxandroid:id="@+id/checkbox3"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:text="@string/sing"/><CheckBoxandroid:id="@+id/checkbox4"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:text="@string/game"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:orientation="horizontal"><CheckBoxandroid:id="@+id/checkbox5"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:textSize="16sp"android:text="@string/dacing"/><CheckBoxandroid:id="@+id/checkbox6"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:text="@string/Kongfu"/><CheckBoxandroid:id="@+id/checkbox7"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:text="@string/running"/><CheckBoxandroid:id="@+id/checkbox8"android:layout_height="wrap_content"android:layout_weight="1"android:layout_width="0dp"android:text="@string/swimming"/></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="自我评价:"android:textSize="20sp"/></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="勤劳"android:textSize="20sp"/><RatingBarandroid:id="@+id/rtMarks1"style="@style/RadingStyle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="true"android:isIndicator="false"android:stepSize="0.1"android:numStars="5" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="上进"android:textSize="20sp"/><RatingBarandroid:id="@+id/rtMarks2"style="@style/RadingStyle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="true"android:isIndicator="false"android:stepSize="0.1"android:numStars="5" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="勇敢"android:textSize="20sp"/><RatingBarandroid:id="@+id/rtMarks3"style="@style/RadingStyle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="true"android:isIndicator="false"android:stepSize="0.1"android:numStars="5" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:text="诚实"android:textSize="20sp"/><RatingBarandroid:id="@+id/rtMarks4"style="@style/RadingStyle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="true"android:isIndicator="false"android:stepSize="0.1"android:numStars="5" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/btnReg"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center"android:text="注册" /></LinearLayout></LinearLayout>
</ScrollView>

Java代码

package com.example.qq.myregisterapplication;import android.content.DialogInterface;
import android.support.annotation.IdRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener{//声明组件EditText edtUserName, edtPassWd, edtConfirmPassWd;RadioButton rdMale, rdFeMale;RadioGroup rdgGender;RatingBar rtMarks1,rtMarks2,rtMarks3,rtMarks4;Button btnReg;boolean isYes=true;//状态判断是否可以注册ArrayList<CompoundButton> selected = new ArrayList<>();//用来存储已选取项的集合对象//省份城市的下拉列表private Spinner spinner2;private Spinner spinner1;private List<Map<String, Object>> list;private String[] province;private String[] city0;private String[] city1;private String[] city2;private int[] images;//初始化组件public void initView() {btnReg=(Button)findViewById(R.id.btnReg);edtUserName = (EditText) findViewById(R.id.edtUserName);edtPassWd = (EditText) findViewById(R.id.edtPassWd);edtConfirmPassWd = (EditText) findViewById(R.id.edtConfirmPassWd);rdMale = (RadioButton) findViewById(R.id.rdMale);rdFeMale = (RadioButton) findViewById(R.id.rdFeMale);rdgGender = (RadioGroup) findViewById(R.id.rdgGender);//注册按钮初始化btnReg=(Button)findViewById(R.id.btnReg);//评分条初始化rtMarks1 = (RatingBar) findViewById(R.id.rtMarks1);rtMarks2 = (RatingBar) findViewById(R.id.rtMarks2);rtMarks3 = (RatingBar) findViewById(R.id.rtMarks3);rtMarks4 = (RatingBar) findViewById(R.id.rtMarks4);//省份城市的下拉列表spinner1 = (Spinner) findViewById(R.id.s_main_spinner1);spinner2 = (Spinner) findViewById(R.id.s_main_spinner2);//多选框的初始化,注册监听事件int chk_id[]={R.id.checkbox1, R.id.checkbox2, R.id.checkbox3, R.id.checkbox4, R.id.checkbox5, R.id.checkbox6, R.id.checkbox7, R.id.checkbox8};for (int id:chk_id) {CheckBox chk= (CheckBox) findViewById(id);chk.setOnCheckedChangeListener(this);}}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.register);initView();rtb();//调用评分条方法//用户名判断监听事件edtUserName.setOnFocusChangeListener(new View.OnFocusChangeListener() {@Overridepublic void onFocusChange(View v, boolean hasFocus) {String name = edtUserName.getText().toString();if (name.length() <= 2) {Toast.makeText(MainActivity.this, "用户名长度不能小于2", Toast.LENGTH_LONG).show();}}});//密码判断监听事件edtPassWd.setOnFocusChangeListener(new View.OnFocusChangeListener() {@Overridepublic void onFocusChange(View v, boolean hasFocus) {String firstPwd = edtPassWd.getText().toString();if (firstPwd.length() < 6 || firstPwd.length() > 12) {Toast.makeText(MainActivity.this, "密码长度必须在6~12位之间", Toast.LENGTH_LONG).show();}}});edtConfirmPassWd.setOnFocusChangeListener(new View.OnFocusChangeListener() {@Overridepublic void onFocusChange(View v, boolean hasFocus) {String firstPwd = edtPassWd.getText().toString();if (firstPwd.length() < 6 || firstPwd.length() > 12) {Toast.makeText(MainActivity.this, "密码长度必须在6~12位之间", Toast.LENGTH_LONG).show();}}});//注册按钮的监听事件btnReg.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (!(edtPassWd.getText().toString().equals(edtConfirmPassWd.getText().toString()))) {Toast.makeText(MainActivity.this, "两次密码必须一致", Toast.LENGTH_SHORT).show();isYes = false;}if (isYes) {Toast.makeText(MainActivity.this, "注册成功!", Toast.LENGTH_SHORT).show();AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);builder.setMessage("确认注册?");builder.setPositiveButton("是", new AlertDialog.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}});} else {Toast.makeText(MainActivity.this, "注册不成功!", Toast.LENGTH_SHORT).show();}}});//单选按钮的监听事件rdgGender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {switch (checkedId) {case R.id.rdMale:Toast.makeText(MainActivity.this, "男", Toast.LENGTH_LONG).show();case R.id.rdFeMale:Toast.makeText(MainActivity.this, "女", Toast.LENGTH_LONG).show();}}});//获取省份城市数据images = new int[]{R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};province = new String[]{"云南省", "河南省", "海南省"};city0 = new String[]{"昆明市", "丽江市", "大理市"};city1 = new String[]{"郑州市", "洛阳市", "信阳市"};city2 = new String[]{"海口市", "三亚市", "儋州市"};list = new ArrayList<>();//数组列表存放数据for (int i = 0; i < province.length; i++) {//数据以hashMap的形式保存Map<String, Object> map = new HashMap<>();map.put("titles", province[i]);map.put("images", images[i]);map.put(province[0], city0[i]);map.put(province[1], city1[i]);map.put(province[2], city2[i]);list.add(map);//数据源}//实例化适配器(simpleAdapter是一个装的类型比较宽泛的容器)SimpleAdapter simpleAdapter = new SimpleAdapter(this, list, android.R.layout.activity_list_item, new String[]{"titles", "images"}, new int[]{android.R.id.text1, android.R.id.icon});spinner1.setAdapter(simpleAdapter);//容器与下拉列表控件绑定在一起//给下拉框设置点击事件spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {SimpleAdapter simpleAdapter2 = new SimpleAdapter(MainActivity.this, list, android.R.layout.activity_list_item, new String[]{"images", province[i]}, new int[]{android.R.id.icon, android.R.id.text1});spinner2.setAdapter(simpleAdapter2);}@Overridepublic void onNothingSelected(AdapterView<?> adapterView) {}});}//复选框按钮的监听事件(继承了接口并重写了方法implements CompoundButton.OnCheckedChangeListener)@Overridepublic void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {if(isChecked){                      //选项被选取selected.add(compoundButton);   //添加到集合中String msg = "";for(CompoundButton chk : selected){msg += chk.getText()+",";}Toast.makeText(this, "爱好:"+msg, Toast.LENGTH_SHORT).show();}}//评分条的方法public void rtb(){RatingBar rt[]={rtMarks1,rtMarks2,rtMarks3,rtMarks4};for(int i=0;i<4;i++) {rt[i].setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {@Overridepublic void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {rating+=rating;Toast.makeText(MainActivity.this, "星级:" + String.valueOf(rating),Toast.LENGTH_LONG).show();}});}}
}

运行效果图

Android-注册界面相关推荐

  1. android注册界面高级,Android用户注册界面简单设计

    本文实例为大家分享了Android用户注册界面的设计,供大家参考,具体内容如下 I. 实例目标 设计一个用户注册界面,在其中要使用到一些基础控件,如 文本框.编辑框.按钮.复选框等控件 II. 技术分 ...

  2. android中注册用户界面,Android用户注册界面

    搜索热词 先给大家展示下界面效果图,感觉满意,请参考实现代码. Main.xml源码 android:layout_width="match_parent" android:lay ...

  3. Android Studio开发:简单的登录注册界面

    Android开发:编写简单的登录界面与注册界面 1.登录界面布局 1.1主布局的布局方式是垂直布局,第一个TextView控件在顶部居中布置,显示"用户登录 "字样 <Te ...

  4. Android开发:登录/注册界面的编写

    目录 新建一个空项目(或Activity) 在xml中绘制登录界面 关掉ActionBar 运行(最终效果图) 后记 在实际开发中,几乎所有的APP都会涉及到用户注册/登录页面的制作,因此本文以And ...

  5. Android实例开发中登录注册界面的框架实现(android studio)

    小项目框架 今天用QQ的时候想到了,不如用android studio 做一个类似于这样的登录软件.当然QQ的实现的功能特别复杂,UI界面也很多,不是单纯的一时新奇就可以做出来的.就是简单的实现了一些 ...

  6. 高仿Android QQ2012登陆界面和注册界面

    最近工作比较轻松,项目不忙,所以闲着的时间去研究了自己比较感兴趣的UI界面,确实漂亮的UI能给用户带来良好的体验,在android应用中一直尤为重要,这次模仿的是QQ2012Android版的的最新登 ...

  7. 使用层级观察器hierarchyviewer综合各种布局实现Android QQ2012登陆界面和注册界面...

    最近工作比较轻松,项目不忙,所以闲着的时间去研究了自己比较感兴趣的UI界面,确实漂亮的UI能给用户带来良好的体验,在android应用中一直尤为重要,这次模仿的是QQ2012Android版的的最新登 ...

  8. Android音乐播放器(二)登录注册界面

    这是去年大二做的一个简单音乐播放器项目:是尽可能模仿酷狗音乐写的,具体实现的功能如下: 1:启动动画:点击运行程序会出现一个两秒钟的视频,类似酷狗音乐的启动动画一样,非常可观! 2:登录注册界面:输入 ...

  9. Android入门实例三 注册界面的设计与实现

    注册界面的设计与实现 1.简介 这次小实验通过RadioButton(单选按钮).CheckBox(复选框)等组件实现一些个人信息的录入,同时介绍了如何使用带图片的Toast反馈信息. 2.源码 2. ...

  10. Android用户登录注册界面

    用户登录注册界面开发及用户信息管理案例详解 刚开始接触Android编程,这算是我写的第一个简单工程,主要功能有:用户登录.注册.注销.修改密码.记住密码共5个基本操作,其内容涉及到以下几点: 1:B ...

最新文章

  1. 多线程实现生产者消费者模型
  2. 第十五届全国大学生智能汽车竞赛深度学习组别预选赛提交作品队伍
  3. 利用Maven搭建Spring开发环境 【转】
  4. 网络推广专员教你如何做好长尾关键词优化?
  5. 用掘金-Markdown 官方语法总结大全
  6. Vue.js 2.x render 渲染函数 JSX
  7. html页面加文字横向滚动,js实现文字横向滚动
  8. -bash:XXX: command not found报错(云服务centos)
  9. oc知识点 类的扩展
  10. super构造方法为什么给子类赋值_【Java学习 | Javase】super
  11. Go条件语句、switch和循环语句
  12. 记一次oracle安装错误:INFO: //usr/lib64/libstdc++.so.5: undefined reference to `memcpy@GLIBC_2.14'...
  13. 成都文理学院计算机一级还没考过,两次查成绩不一致,合格成不合格?成都文理学院官方回应...
  14. 算法动画图解 | 被 “废弃“ 的 Java 栈,为什么还在用
  15. JMeter详细使用手册
  16. 流形上的预积分(下)
  17. LIO-SAM_based_relocalization运行kitti回环序列并保存轨迹评估(一)——————源码的分析
  18. jq身份证号验证(详细)
  19. 小程序里显示店铺地址,可在地图上查看,可点击导航到店铺
  20. 浏览器有新消息之后,图标在电脑任务栏闪烁提示

热门文章

  1. 您的外卖为什么凉了?
  2. 阿里云SSL证书免费申请方法(图文教程)
  3. 在计算机系统中 屏幕的显示分辨率为,如何调整win7的分辨率?计算机系统分辨率调整步骤[详细说明]...
  4. 电磁阀位、通、开/闭原理精髓
  5. MPC5744P-SIUL2模块(GPIO和多路复用功能)
  6. 淘宝运营之关于爆款你不知道的事
  7. 迅雷诉超级兔子侵权案9日开庭
  8. 使用 LSTM 进行多变量时间序列预测
  9. 跨境电商独立站卖家如何做EDM邮件营销?
  10. 软件测试信息采集系统案例实践,软件测试课件.ppt