读书笔记[Android Beginning 2] chapter 5 Employing Basic Widgets
来源:互联网 发布:大富豪5.3棋牌源码 编辑:程序博客网 时间:2024/04/29 21:44
Every GUI toolkit has some basic widgets: fields, labels, buttons, and so on.
Assigning Labels
The simplest widget is the label, referred to in Android as a TextView. As in most GUI toolkits, labels are bits of text that cannot be edited directly by users. Typically, they are used to identify adjacent widgets.
you can create a label by creating a TextView instance. More commonly, though, you will create labels in XML layout files by adding a TextView element to the layout, with an android:text property to set the value of the label itself.
TextView properties: TextView has many other attributes, you should refer to the Android SDK.
android:typeface: Sets the typeface to use for the label (e.g., monospace).
android:textStyle: Indicates that the typeface should be made bold (bold), italic (italic), or bold and italic (bold|italic).
android:textColor: Sets the color of the label’s text, in RGB hex format (e.g., #FF0000 for red).
Usage:
android:typeface="sans"
android:textStyle="bold|italic"
android:textColor="#ff0000"
Note: quotation marks are neccessory.
Button, Button, Who’s Got the Button?
Button is a subclass of TextView, so everything discussed in the preceding section also applies to formatting the face of the button.
However, Android 1.6 adds a new feature for the declaration of the “on-click” listener for a Button. In addition to the classic approach of defining some object (such as the activity) as implementing the View.OnClickListener interface, you can now take a somewhat simpler approach:
Define some method on your Activity that holds the button that takes a single View parameter, has a void return value, and is public.
In your layout XML, on the Button element, include the android:onClick attribute with the name of the method you defined in the previous step.
public void someMethod(View theButton) {
// do something useful here
}
Then you could use this XML declaration for the Button itself, including
android:onClick:
<Button
android:onClick="someMethod"
...
/>
注意:这种方法必须用在android 1.6以上
参考添加Listener的办法:http://hellsing42.iteye.com/blog/564772
Fleeting Images
Android has two widgets to help you embed images in your activities: ImageView and ImageButton. As the names suggest, they are image-based analogues to TextView and Button, respectively.
Each widget takes an android:src attribute (in an XML layout) to specify which picture to use. These usually reference a drawable resource。
You can also set the image content based on a Uri from a content provider via setImageURI().
参考使用setImageURI的办法: http://stackoverflow.com/questions/3870638/how-to-use-setimageuri-android
Uri imgUri=Uri.parse("file:///data/data/MYFOLDER/myimage.png");
Fields of Green. Or Other Colors.
fields are the third anchor of most GUI toolkits. In Android, they are implemented via the EditText widget, which is a subclass of the TextView used for labels.
EditText has many other properties that will be useful to you in constructing fields, including the following:
android:autoText: Controls if the field should provide automatic spelling assistance.
android:capitalize: Controls if the field should automatically capitalize the first letter of entered text (useful for name or city fields, for example).
android:digits: Configures the field to accept only certain digits. android:singleLine: Controls if the field is for single-line input or multiple-line input (e.g., does pressing Enter move you to the next widget or add a newline?).
- 读书笔记[Android Beginning 2] chapter 5 Employing Basic Widgets
- 读书笔记[Android Beginning 2] chapter 1
- 读书笔记[Android Beginning 2] chapter 2 Create a Skeleton Application
- 读书笔记[Android Beginning 2] chapter 4 Using XML-Based Layouts
- 读书笔记 - Beginning Linux Programming - Chapter 2 Shell Programming
- pyGTK_读书笔记_Tutorial Chapter 4_Packing Widgets
- Chapter 5 Basic Drawing
- 读书笔记 - Beginning Linux Programming - Chapter 1 Getting Started
- Android基础 【Chapter-3】Android widgets(Android控件)
- Chapter 2 Basic Programming Model
- Chapter 3: Screen Widgets
- Chapter 4: Form Widgets
- perfbook读书笔记 chapter 2
- Chapter 5: Other View Element Types in Screen Widgets
- Chapter 7 Beginning CXControl
- Beginning Python Chapter 21
- Beginning Python Chapter 22
- Beginning Python Chapter 25
- 010脚本编写入门
- 字符编码简介:ASCII,Unicode,UTF-8
- 裁剪图片
- Oracle 常用总结
- HTML 脚本、事件属性
- 读书笔记[Android Beginning 2] chapter 5 Employing Basic Widgets
- 报表中的Excel操作之Aspose.Cells(Excel模板)
- SQL Server 中关于EXCEPT和INTERSECT的用法
- string 用法
- strtok
- Const,Const函数,Const变量,函数后面的Const
- eclipse +MyEclipse5.5+struts2+MySQL5
- cctype 原来C ctype.h 几个函数理解
- 敏捷思维- 架构设计中的方法学