android-UI组件(二):TextView及其子类
来源:互联网 发布:沐足软件 编辑:程序博客网 时间:2024/05/21 20:29
下面列出了TextView及其子类的类图关系:
TextView与EditText具有很多相似的地方,它们最大的不同在于:TextView不允许用户编辑文本内容,EditText允许用户编辑文本内容。
TextView提供大量XML属性,这些XML属性适用于TextView以及它的子类,下面列出这些XML属性以及相关方法:
1、EditText:
EditText组件最重要的属性是inputType,该属性相当于HTML的<input .../>元素的type属性。
EditText派生如下两个子类:
(1)AutoCompleteTextView:带有自动完成功能的EditText,该类常与Adapter结合使用
(2)ExtractEditText:并不是UI组件,而使EditText组件的底层服务类,负责提供全屏输入法支持
2、Button:
Button继承自TextView,主要在UI界面上生成一个按钮,当用户单击时,触发一个onClick事件,
可以使用android:background属性为按钮增加背景颜色或者背景图片,如果要实现动态图片,则使用Drawable对象来实现。
下面只是一个简单的例子:
activity_button.xml如下:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".ButtonActivity" > <TableRow> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:shadowColor="#aa5" android:shadowDx="5" android:shadowDy="5" android:shadowRadius="1" android:text="@string/bn1" android:textSize="12pt" /> </TableRow> <TableRow> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/red" android:text="@string/bn2" android:textSize="10pt" > </Button> </TableRow> <TableRow> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_selector" android:text="@string/bn3" android:textSize="11pt" > </Button> </TableRow></TableLayout>button_selector.xml如下:
<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/blue" android:state_pressed="true"></item> <item android:drawable="@drawable/purple" android:state_pressed="false"></item></selector>这里的button3就是实现的按钮动态图片,要好好体会。
(1)RadioButton:单选按钮,每次只能选中一个,常与RadioGroup一起使用
(2)CheckBox:复选框,每次可以选中若干个
(3)ToggleButton:状态开关按钮
(4)Switch:开关
ToggleButton、Switch与CheckBox很相似,但是它们之间的主要区别在功能上,ToggleButton、Switch通常用于切换程序中的某种状态,
ToggleButton支持的XML属性:
Switch支持的XML属性:
3、AnalogClock/DigitalClock :
DigitalClock本身就继承了TextView,只是里面显示的内容是当前时间,DigitalClock继承了TextView的所有属性。
AnalogClock继承了View组件,重写View的OnDraw方法,它会在View绘制模拟时钟,AnalogClock的属性如下:
4、Chronometer:
计时器组件,该组件与DigitalClock一样,都继承TextView,但是Chronometer并不显示当前时间,而是显示从某个起始时间开始,一共过去多少时间。
Chronometer支持如下的方法:
下面是几种SystemClock的常用方法:
- android-UI组件(二):TextView及其子类
- UI组件:TextView及其子类
- UI组件:TextView及其子类
- Android用户界面 UI组件--TextView及其子类(一) TextView
- Android用户界面 UI组件--TextView及其子类(二) Button,selector选择器,sharp属性
- Android用户界面 UI组件--TextView及其子类(四) Chronometer计时器
- UI组件之TextView及其子类(二)RadioButton和CheckBox
- UI组件之TextView及其子类(四)AnalogClock,DigitalClock
- UI组件之TextView及其子类(五)计时器Chronometer
- UI组件之TextView及其子类
- [阶段二]Android UI TextView及其子类
- UI组件之TextView及其子类(一)TextView和EditText
- ui.TextView及其子类
- Android基础UI篇------TextView及其子类
- Android用户界面 UI组件--AdapterView及其子类(二) AdapterViewAnimator及其子类
- UI组件之ImageView及其子类(二)ImageButton ,ZoomButton
- Android用户界面 UI组件--TextView及其子类(三) EditView以及各种Span文字样式讲解
- Android用户界面 UI组件--TextView及其子类(五) DigitalClock,AnalogClock,RadioButton,CheckBox,ToggleButton汇总
- IPC——共享内存与信号灯的基本函数整理
- week7_2
- 设一个长度为10的整型数组, 0)要求每个元素的值通过scanf输入,输入完成后, 1)请顺序输出这些整数, 2)请倒序输出这些整数, 3)输出这些数中的最大值, 4)输出这些数中的最小值
- Linux操作命令总结(二)
- Android 实用工具Hierarchy Viewer实战
- android-UI组件(二):TextView及其子类
- 简单工厂模式
- memcpy和memmove的区别与联系
- POJ 2395
- Linux I/O Performance Tests using dd
- Java类加载机制
- sicily 1935. 二叉树重建
- POJ 2385 Apple Catching (DP)
- 中断处理(中断向量寄存器)