Heres one way to open a file called thehelptxt InputStream iFile getResources

Heres one way to open a file called thehelptxt

This preview shows page 92 - 101 out of 112 pages.

Here’s one way to open a file called the_help.txt : InputStream iFile = getResources() .openRawResource(R.raw.the_help);
Image of page 92

Subscribe to view the full document.

References to Resources You can reference resources instead of duplicating them. For example: Your application might want to reference a single string resource in multiple string arrays. The most common use of resource references is in layout XML files, where layouts can reference any number of resources to specify attributes for layout colors, dimensions, strings, and graphics. Another common use is within style and theme resources. Resources are referenced using the following format: @resource_type/variable_name
Image of page 93
References to Resources (Cont’d) Recall that earlier we had a string array of soup names. If we want to localize the soup listing, a better way to create the array is to create individual string resources for each soup name and then store the references to those string resources in the string array (instead of the text). To do this, we define the string resources in the res/strings.xml file like this: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Application Name</string> <string name="chicken_soup">Organic Chicken Noodle</string> <string name="minestrone_soup">Veggie Minestrone</string> <string name="chowder_soup">New England Clam Chowder</string> </resources>
Image of page 94

Subscribe to view the full document.

References to Resources (Cont’d) Then, we can define a localizable string array that references the string resources by name in the res/arrays.xml file like this: <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="soups"> <item>@string/minestrone_soup</item> <item>@string/chowder_soup</item> <item>@string/chicken_soup</item> </string-array> </resources>
Image of page 95
References to Resources (Cont’d) You can also use references to make aliases to other resources. For example: You can alias the system resource for the OK string to an application resource name by including the following in your strings.xml resource file: <?xml version="1.0" encoding="utf-8"?> <resources> <string d="app_ok">@android:string/ok</string> </resources>
Image of page 96

Subscribe to view the full document.

Working with Layouts Much as Web designers use HTML, user interface designers can use XML to define Android application screen elements and layout. A layout XML resource is where many different resources come together to form the definition of an Android application screen. Layout resource files are included in the res/layout/ directory and are compiled into the application package at build time. Layout files might include many user interface controls and define the layout for an entire screen or describe custom controls used in other layouts.
Image of page 97
Working with Layouts (Cont’d)
Image of page 98

Subscribe to view the full document.

Working with Layouts (Cont’d) The activity_simple_resource_view.xml layout file that displays this screen references a number of other resources, including colors, strings, and dimension values, all of which were defined in the strings.xml , styles.xml , colors.xml , and dimens.xml resource files.
Image of page 99
Working with Layouts (Cont’d) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ""
Image of page 100

Subscribe to view the full document.

Image of page 101
  • Summer '16

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes