TAILIEUCHUNG - Android SDK (phần 3)

Externalizing Resources ❘ 67 LISTING 3-3: Simple menu layout resource Using Resources As well as the resources you create, Android supplies several system resources that you can use in your applications. The resources can be used directly from your application code and can also be referenced from within other resources (., a dimension resource might be referenced in a layout definition). Later in this chapter you’ll learn how to define alternative resource values for different languages, locations, and hardware. It’s important to note that when using resources you cannot choose a particular specialized version. Android will automatically select the most. | Externalizing Resources 67 LISTING 3-3 Simple menu layout resource Available for downloadon xml version encoding utf-8 menu xmlns android http apk res android item android id @ id menu_refresh android title Refresh item android id @ id menu_settings android title Settings menu Using Resources As well as the resources you create Android supplies several system resources that you can use in your applications. The resources can be used directly from your application code and can also be referenced from within other resources . a dimension resource might be referenced in a layout definition . Later in this chapter you ll learn how to define alternative resource values for different languages locations and hardware. It s important to note that when using resources you cannot choose a particular specialized version. Android will automatically select the most appropriate value for a given resource identifier based on the current hardware and device settings. Using Resources in Code You access resources in code using the static R class. R is a generated class based on your external resources and created when your project is compiled. The R class contains static subclasses for each of the resource types for which you ve defined at least one resource. For example the default new project includes the and subclasses. Zh If you are us ng he ADT plug-in .n he R class will be created you a e usmg e pugm n cpse e r ctass w e cieai C automatically when you make any change to an external resource f le or folder. If you are not using the plug-in use the AAPT tool to compile your project and generate the R class. R is a compiler-generated class so don t make any manual modifications to it as they will be lost when the file is regenerated. Each of the subclasses within R exposes its associated resources as variables with the variable names matching the resource identifiers for example or .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.