|
| 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/ |
| 12 | + icon.png |
| 13 | + |
| 14 | + layout/ |
| 15 | + main.xml |
| 16 | + |
| 17 | + values/ |
| 18 | + strings.xml |
| 19 | + |
| 20 | +In order to get the build system to recognize Android resources, set the build action to |
| 21 | +"AndroidResource". The native Android APIs do not operate directly with filenames, but |
| 22 | +instead operate on resource IDs. When you compile an Android application that uses resources, |
| 23 | +the build system will package the resources for distribution and generate a class called "Resource" |
| 24 | +(this is an Android convention) that contains the tokens for each one of the resources |
| 25 | +included. For example, for the above Resources layout, this is what the Resource class would expose: |
| 26 | + |
| 27 | +public class Resource { |
| 28 | + public class Drawable { |
| 29 | + public const int icon = 0x123; |
| 30 | + } |
| 31 | + |
| 32 | + public class Layout { |
| 33 | + public const int main = 0x456; |
| 34 | + } |
| 35 | + |
| 36 | + public class Strings { |
| 37 | + public const int first_string = 0xabc; |
| 38 | + public const int second_string = 0xbcd; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or |
| 43 | +Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string |
| 44 | +to reference the first string in the dictionary file values/strings.xml. |
0 commit comments