<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">注册界面的设计效果如下:                                                                                                                                                                                                                                                                    </span>

今天主要讲的Toast的用法:

1.默认Toast

Toast.makeText(context, text, duration).show();//context为使用的上下文,text表示要显示的字符串,duration表示显示的时间,值为:Toast.LENGTH_LONG,Toast.LENGTH_SHORT

切记在引用的时候不要忘记.show。

2.自定义Toast显示位置

Toast toast = Toast.makeText(this, "这是自定义位置的toast", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);//设置toast显示的位置
        toast.show();

3.带图标的Toast

Toast toast = Toast.makeText(this, "这是带图标的toast", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);//设置toast显示的位置
        LinearLayout toastview = (LinearLayout)toast.getView();//获取Toast的view对象
        ImageView image = new ImageView(this);
        image.setImageResource(R.drawable.ic_launcher);
        toastview.addView(image);
        toast.setView(toastview);//将view显示在Toast上
        toast.show();

好了,下面介绍界面的布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="请输入您的用户名:"/><EditText android:id="@+id/editText1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:hint=" "/><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="请选择您的性别:"/><RadioGroupandroid:id="@+id/radioGroup1"android:orientation="horizontal"android:layout_width="wrap_content"android:layout_height="wrap_content"><RadioButton android:id="@+id/maleButton"android:text="男"android:layout_width="wrap_content"android:layout_height="wrap_content"/><RadioButton android:id="@+id/femaleButton"android:text="女"android:layout_width="wrap_content"android:layout_height="wrap_content"/></RadioGroup><TextViewandroid:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="请选择您的爱好:"/><CheckBox android:id="@+id/singBox"  android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="唱歌"/><CheckBox android:id="@+id/danceBox"  android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="跳舞"/><CheckBox android:id="@+id/drawBox"  android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="画画"/><Button android:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="注  册"/>
</LinearLayout>

MainActivity中的代码如下:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.ToggleButton;public class MainActivity extends Activity {private RadioGroup genderGroup;// 定义单选按钮组private RadioButton maleBtn, femaleBtn;private CheckBox singCheckBox, danceCheckBox, drawCheckBox;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);genderGroup = (RadioGroup) findViewById(R.id.radioGroup1);maleBtn = (RadioButton) findViewById(R.id.maleButton);femaleBtn = (RadioButton) findViewById(R.id.femaleButton);singCheckBox = (CheckBox) findViewById(R.id.singBox);danceCheckBox = (CheckBox) findViewById(R.id.danceBox);drawCheckBox = (CheckBox) findViewById(R.id.drawBox);// 对RadioGroup注册事件监听器genderGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {String sexString = "";// 定义显示性别的字符串变量if (maleBtn.getId() == checkedId) {// 根据对checkedId判断用户的选项sexString = sexString + maleBtn.getText();// 调用了getText()方法获得按钮文本} else if (femaleBtn.getId() == checkedId) {sexString = sexString + femaleBtn.getText();}Toast.makeText(MainActivity.this, "您选择的性别是:" + sexString,Toast.LENGTH_LONG).show();}});// 下面分别对每个CheckBox实现事件监听singCheckBox.setOnCheckedChangeListener(new Listener());danceCheckBox.setOnCheckedChangeListener(new Listener());drawCheckBox.setOnCheckedChangeListener(new Listener());}class Listener implementsandroid.widget.CompoundButton.OnCheckedChangeListener {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {String str = "";// 定义显示爱好的字符串变量if (singCheckBox.isChecked()) {// 调用isChecked()方法,判断哪个选项被选中str = str + singCheckBox.getText();}if (danceCheckBox.isChecked()) {str = str + danceCheckBox.getText();}if (drawCheckBox.isChecked()) {str = str + drawCheckBox.getText();}Toast.makeText(MainActivity.this, "您选择的爱好是:" + str,Toast.LENGTH_LONG).show();}}
}

注册界面的设计与实现相关推荐

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

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

  2. Python-GUI PyQT5案例:注册界面窗体设计(含扇形菜单)

    QPushButton {font: 10pt "楷体";border-radius: 25px;background-color: rgb(254, 83, 123);borde ...

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

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

  4. 右侧按钮登录注册html,翻转式用户登录注册界面设计

    这是一款非常实用的翻转式用户登录注册界面设计效果.该用户登录注册界面使用纯CSS3来制作,在用户点击登录和注册两个按钮时,登录和注册界面可以以水平翻转的方式来回切换,效果非常的酷. 制作方法 HTML ...

  5. JavaScript + CSS/CSS3 + HTML 网页登陆 + 注册界面设计

    登陆界面设计 撸代码之前先来看一看效果图: 登陆界面由一个简单的表单(头像.用户名.密码.登陆按钮.记住我.取消.忘记密码),创建了一个CSS3的缩放效果构成.需要做浏览器(Firefox.Safar ...

  6. swing界面设计之登录注册界面

    开发环境:Eclipse Neon.3 Release (4.6.3) 我用的为javaee版本的,为了便于设计界面,需要安装windowbuilder插件,可以直接在marketplace里搜索到. ...

  7. html5漂亮的登录与注册界面设计,漂亮的网页登陆/注册表单设计

    漂亮的网页登陆/注册表单设计 7月 4, 2012 评论 Sponsor 网页设计中登陆和注册表单是非常常用的,而且使用率也非常高,一个表单的设计其实也不是简单的事情,你要考虑很多用户体验,有的喜欢把 ...

  8. 【HTML界面设计(一)】底层模板、管理员界面、注册界面

    记录2020年写的HTML模板.(需要自己下jQuery文件) 一.底层模板 自适应屏幕大小,左右分层. html代码 <!DOCTYPE html> <html lang=&quo ...

  9. 基于RSA加密和Tkinter可视化的密码存储程序(可用于期末作业设计、Python练习、实用应用;抗错误输入、抗密码盗取)二:登录、注册界面

    此篇接上篇,有兴趣的可以去主页或专栏看看,没有的话咱直接开始: 基于RSA加密和Tkinter可视化的密码存储程序(可用于期末作业设计.Python练习.实用应用:抗错误输入.抗密码盗取)一:思路介绍 ...

最新文章

  1. codeforces524E
  2. Linkedin Camus的使用
  3. 将excel转为python的字典_python读取excel表并把数据转存为字典
  4. jpanel把原本内容覆盖掉_A5:APP关键词覆盖你该了解哪些
  5. 17秋 软件工程 团队第五次作业 Alpha Scrum2
  6. 中文设置_lol手游台服怎么设置中文?lol手游台服中文的具体设置教程
  7. ssis配置文件优先级_SSIS优先约束概述
  8. 【Python-3.5】变量命名规范
  9. Cgroups控制cpu,内存,io示例
  10. 基于linker实现so加壳补充从dex中加载so
  11. C++ 什么是句柄?为什么会有句柄?HANDLE
  12. python打包加壳_转:Python用PyInstaller打包笔记
  13. 初中计算机教学进度表,信息技术教学计划范文
  14. 探索多层次内存系统的页面管理设计空间Exploring the Design Space of Page Management for Multi-Tiered Memory Systems
  15. php excel 进度,在php中生成Excel文件时显示进度条
  16. CSS技巧之精灵图/字体图标/画三角/用户页面样式/vertical-align
  17. 什么是身份证OCR接口
  18. BZOJ 1124 [POI2008]枪战Maf 贪心+乱搞
  19. url短网址 java_url.cn短网址生成api接口(腾讯短链接url生成)
  20. visio中如何画无箭头直线

热门文章

  1. linux看到的分区重复,找到了linux分区顺序错乱修复方法
  2. cheked复选框返回值的时候选中
  3. 数据结构课本学习 --单链表类定义
  4. JS基础-Array对象手册
  5. 信号处理函数(2)-sigismember()
  6. 利用大数据技术探索“数字公民”创新
  7. 《Java编程思想》读书笔记 第十三章 字符串
  8. windows批处理實例
  9. 配置linux下oracle sqlplus/rman等历史记录回调功能
  10. Postfix配置文档