Đang chuẩn bị liên kết để tải về tài liệu:
Bắt Đầu Với Android (P.2)
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'bắt đầu với android (p.2)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Murphy_2419-8C06.fm Page 27 Thursday April 9 2009 5 35 PM CHAPTER 6 Employing Basic Widgets EveryGUI toolkit has some basic widgets fields labels buttons etc. Android s toolkit is no different in scope and the basic widgets will provide a good introduction as to how widgets work in Android activities. Assigning Labels The simplest widget is the label referred to in Android as a TextView. Like in most GUI toolkits labels are bits of text not editable directly by users. Typically they are used to identify adjacent widgets e.g. a Name label before a field where one fills in a name . In Java 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. If you need to swap labels based on certain criteria such as internationalization you may wish to use a resource reference in the XML instead as will be described in Chapter 9. TextView has numerous other properties of relevance for labels such as android typeface to set the typeface to use for the label e.g. monospace android textStyle to indicate that the typeface should be made bold bold italic italic or bold and italic bold_italic android textColor to set the color of the label s text in RGB hex format e.g. FF0000 for red For example in the Basic Label project you will find the following layout file xml version 1.0 encoding utf-8 TextView xmlns android http schemas.android.com apk res android android layout_width fill_parent android layout_height wrap_content android text You were expecting something profound 27 Murphy_2419-8C06.fm Page 28 Thursday April 9 2009 5 35 PM 28 CHAPTER 6 EMPLOYING BASIC WIDGETS As you can see in Figure 6-1 just that layout alone with the stub Java source provided by Android s project builder e.g. activityCreator gives you the application. Figure 6-1. The LabelDemo sample application Button Button Who s Got the Button We ve