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. 设置select下拉框不可修改的→“四”←种方法
  2. cifs------网络文件系统(1)
  3. java readline读取最后一行_java的转换流解析
  4. 原生 AJAX的相关介绍
  5. Enterprise search Callstack in runtime
  6. 腐蚀和膨胀(erode and dilate)
  7. 两张照片重叠处半透明_那些悬浮在空中的照片是怎么拍的?
  8. vue ui创建项目报错:Cannot read property ‘indexOf‘ of undefined解决方法
  9. python3_configparser模块详解
  10. SQL2K数据库开发七之表操作添加删除和修改列
  11. java 10000阶乘_java大数阶乘优化
  12. 中国联通沃支付echop支付插件
  13. 轻量级linux桌面环境,Linux发行版最为轻量级的桌面环境之一Xfce 桌面
  14. 多对多关系需要建立中间表_【数据库基础】为什么需要三张表之多对多表结构设计...
  15. win10注册mysql服务_win10下搭建MySQL服务
  16. esxi服务器下虚拟机Ubuntu系统搭建PPPoE拨号服务
  17. AnyPi智能语音音箱方案 智能蓝牙WIFI音箱方案开发 DuerOS及Alexa平台
  18. usc计算机科学硕士分支方向,一次说清北美计算机科学硕士的项目,选校,申请,排名,难度...
  19. Redis高级应(2)-事务以及LUA脚本
  20. MTTR/MTTF/MTBF图解

热门文章

  1. mysql 8.0 1114 Error, The table /tmp/#sql~~~ is full
  2. 7.阿布云代理服务器试用
  3. 需要哈萨克语电脑板输入法的联系
  4. idea中导入python项目
  5. vue cli项目升级--vue cli3升级到vue cli4
  6. arima基本原理_时间序列 :ARIMA模型-原理
  7. 【老骥伏枥,志在千里】今天来看看xmlHttpRequest
  8. 手机销售系统设计与实现
  9. 写给六年前自己的一封信
  10. 多所高校月饼上新!神仙月饼打架~好卷呀~