AttendanceSupport

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

AboutResources.txt (1772B)


      1 Images, layout descriptions, binary blobs and string dictionaries can be included 
      2 in your application as resource files.  Various Android APIs are designed to 
      3 operate on the resource IDs instead of dealing with images, strings or binary blobs 
      4 directly.
      5 
      6 For example, a sample Android app that contains a user interface layout (main.xml),
      7 an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 
      8 would keep its resources in the "Resources" directory of the application:
      9 
     10 Resources/
     11     drawable-hdpi/
     12         icon.png
     13 
     14     drawable-ldpi/
     15         icon.png
     16 
     17     drawable-mdpi/
     18         icon.png
     19 
     20     layout/
     21         main.xml
     22 
     23     values/
     24         strings.xml
     25 
     26 In order to get the build system to recognize Android resources, set the build action to
     27 "AndroidResource".  The native Android APIs do not operate directly with filenames, but 
     28 instead operate on resource IDs.  When you compile an Android application that uses resources, 
     29 the build system will package the resources for distribution and generate a class called
     30 "Resource" that contains the tokens for each one of the resources included. For example, 
     31 for the above Resources layout, this is what the Resource class would expose:
     32 
     33 public class Resource {
     34     public class drawable {
     35         public const int icon = 0x123;
     36     }
     37 
     38     public class layout {
     39         public const int main = 0x456;
     40     }
     41 
     42     public class strings {
     43         public const int first_string = 0xabc;
     44         public const int second_string = 0xbcd;
     45     }
     46 }
     47 
     48 You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main 
     49 to reference the layout/main.xml file, or Resource.strings.first_string to reference the first 
     50 string in the dictionary file values/strings.xml.