Android开发8:UI组件TextView,EditText,Button
版本:Android4.3 API18 学习整理:liuxinming
TextView
概述
TextView类及子类的类图
XML属性
EditText
概述
子类
奉上测试案例:用户输入界面
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="用户名:"
android:textSize="16sp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请填写登录账户"
android:selectAllOnFocus="true"
/>
</TableRow>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="16sp"
/>
<!-- android:inputType="numberPassword" 表明只能接受数字密码 -->
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword"
/>
</TableRow>
<TableRow >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="年龄:"
android:textSize="16sp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
/>
</TableRow>
<TableRow >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="生日:"
android:textSize="16sp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="date"
/>
</TableRow>
<TableRow >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="电话号码:"
android:textSize="16sp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请填写您的电话号码"
android:selectAllOnFocus="true"
android:inputType="phone"
/>
</TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
/>
</TableLayout>
调试效果:
Button
概述
RadioButton,CheckBox
单选按钮、复选框实例
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<TableRow >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别:"
android:textSize="16sp"
/>
<!-- 这里定义一组单选按钮 -->
<RadioGroup android:id="@+id/button01"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
>
<!-- 定义两个单选按钮 -->
<RadioButton android:id="@+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:checked="true"
/>
<RadioButton android:id="@+id/gril"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RadioGroup>
</TableRow>
<TableRow >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="喜欢的美女"
android:textSize="16sp"
/>
<!-- 定义一个垂直的线性布局 -->
<LinearLayout android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<!-- 定义三个复选框 -->
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="大S"
android:checked="true"
/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小S"
/>
</LinearLayout>
</TableRow>
<TextView
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableLayout>
java代码
package com.example.edittext; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView; public class MainActivity extends Activity {
RadioGroup button01;
TextView show; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//获取界面上button01,show两个组件对象
button01 = (RadioGroup) findViewById(R.id.button01);
show = (TextView) findViewById(R.id.show);
//为RadioGroup组件的OnCheck事件绑定事件监听器
button01.setOnCheckedChangeListener(new OnCheckedChangeListener()
{ @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
//根据用户勾选的单选按钮来动态改变tip字符串的值
String tip = checkedId == R.id.boy ? "男人":"女人";
//修改 show 组件中的文本
show.setText(tip);
} });
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
效果
ToggleButton,Switch
AnalogClock,DigitalClock
Chronometer
支持常用方法
Android开发8:UI组件TextView,EditText,Button的更多相关文章
- Android开发 ---基本UI组件3:单选按钮、多选按钮、下拉列表、提交按钮、重置按钮、取消按钮
Android开发 ---基本UI组件2 1.activity_main.xml 描述: 定义一个用户注册按钮 <?xml version="1.0" encoding=&q ...
- Android开发 ---基本UI组件4:拖动事件、评分进度条、圆圈式进度条、进度条控制
Android开发 ---基本UI组件4 1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding=" ...
- Android开发 ---基本UI组件2:图像按钮、单选按钮监听、多选按钮监听、开关
Android开发 ---基本UI组件2 1.activity_main.xml 描述: 定义一个按钮 <?xml version="1.0" encoding=" ...
- Android经常使用UI组件 - TextView
TextView是Android里面用的最多的UI组件,一般使用在须要显示一些信息的时候,其不能输入,仅仅能初始设定或者在程序中改动. 实例:TextViewDemo 执行效果: 代码清单: 布局文件 ...
- Android开发 ---基本UI组件6 :只定义一个listView组件,然后通过BaseAdapter适配器根据数据的多少自行添加多个ListView显示数据
效果图: 1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding="utf-8"?> ...
- Android开发---基本UI组件1:自动拨电话,自动上网,输入框不换行、只输数字、只输文本、只输密码
1.activity_main.xml 描述:构建一个按钮 <?xml version="1.0" encoding="utf-8"?> <L ...
- Android开发 ---基本UI组件7 :分页功能、适配器、滚动条监听事件
效果图: 1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding="utf-8"?> ...
- Android开发 ---基本UI组件8:九宫格布局、setOnItemClickListener()项被选中监听事件
效果图: 1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding="utf-8"?> ...
- Android开发 ---基本UI组件5:监听下拉选项,动态绑定下拉选项、全选/反选,取多选按钮的值,长按事件,长按删除,适配器的使用,提示查询数据,activity控制多按钮
效果图: 效果描述: 1.当点击 1 按钮后,进入选择城市的页面,会监听到你选中的城市名称:动态为Spinner绑定数据 2.当点击 2 按钮后,进入自动查询数据页面,只要输入首字母,就会动态查找以该 ...
随机推荐
- 生成war的jdk版本高于tomcat使用的jdk版本,导致项目不能正常被访问
记录一个耽误30分钟的一个坑: 生成war的jdk版本高于tomcat使用的jdk版本,导致项目不能正常被访问 报404错误
- C语言运算符的优先级
熟悉C语言的同学都知道,C语言众多的运算符及繁琐难记的优先级总是搞得我们这些C初学者头大.那么本文就 对C语言中所有的运算符进行汇总,并对其优先级进行一定的介绍. 这里虽然对所有C运算符的优先级进行了 ...
- mongodb导出命令
./mongoexport -d admin -c col -o col.json 找到了 导出所有数据库的 http://www.jb51.net/article/52498.htm
- CodeForces 132C Logo Turtle (记忆化搜索)
Description A lot of people associate Logo programming language with turtle graphics. In this case t ...
- SVN连接不上
某次我们部门换了场地.SVNserver就连接不上了,后来公司数据中心处理好后,还是连接不上,原来还需刷新自己电脑的DNS. 如需转载,请注明出处http://blog.csdn.net/combat ...
- 具体解释HTML中的window对象和document对象
Window -- 代表浏览器中一个打开的窗体: 对象属性 window //窗体自身 window.self //引用本窗户window=window.self window.name //为窗体命 ...
- (转)12款开源JavaScript库
JavaScipt几乎是所有前端开发人员必会的编程语言,并且,随着各种移动APP的串红,JavaScript还可以用来开发移动应用.除此以外,为了丰富前端/移动开发,有不少开发者推出了各种基于Java ...
- 解决aapt命令在Linux下无法运行的问题
新的一个项目,需要在Linux下执行aapt命令对apk文件进行处理 开发环境: MacBook-Pro:appSecuity zhang$ uname -a Darwin huijundeMacBo ...
- Ubuntu 13.10 下安装node
1.首先更新Ubuntu在线包:sudo apt-get update && sudo apt-get dist-upgrade, 2.默认Ubuntu已经安装python的,具体版本 ...
- 成本卷积报错:CSTPSCEX.explode_sc_cost_flags():40:ORA-01476: 除数为 0
成本卷积请求:供应链成本累计 - 打印报表 运行后报一下错误: MSG-00000: Rollup ID = 236403MSG-00000: Before CSTPSCEX.supply_chain ...