Now go to the Component Tree to make sure the ImageView is selected then browse

Now go to the component tree to make sure the

This preview shows page 107 - 112 out of 112 pages.

Now, go to the Component Tree to make sure the ImageView is selected, then browse to the properties of your ImageView control, and set the src property manually by typing @drawable/flag . Now you see that the graphic shows up in your preview. While we’re at it, select the LinearLayout object and set its background property to the background drawable you added.
Image of page 107

Subscribe to view the full document.

Using Layout Resources Programmatically Objects within layouts, whether Button or ImageView controls, are all derived from the View class. To retrieve a TextView object named TextView01 , called in an Activity class after the call to setContentView() : TextView txt = (TextView) findViewById(R.id.TextView01); You can also access the underlying XML of a layout resource much as you would any XML file. To retrieve the main.xml layout file for XML parsing: XmlResourceParser myMainXml = getResources() .getLayout(R.layout.activity_paris_view); Developers can also define custom layouts with unique attributes.
Image of page 108
Referencing System Resources In addition to the resources included in your project, you can also take advantage of the generic resources provided as part of the Android SDK. You can access system resources much as you would your own resources. The android package contains all kinds of resources, which you can browse by looking in the android.R subclasses. Here, you find system resources for the following: Animation sequences for fading in and out Arrays of email/phone types (home, work, and such) Standard system colors Dimensions for application thumbnails and icons Many commonly used drawable and layout types Error strings and standard button text System styles and themes
Image of page 109

Subscribe to view the full document.

Referencing System Resources (Cont’d) You can reference system resources in other resources such as layout files by specifying the @android package name before the resource. For example: To set the background to the system color for darker gray, you set the appropriate background color attribute to @android:color/darker_gray . You can access system resources programmatically through the android.R class. If we go back to our animation example, we could have used a system animation instead of defining our own. Here is the same animation example again, except it uses a system animation to fade in: ImageView flagImageView = (ImageView)findViewById(R.id.ImageView01); flagImageView.setImageResource(R.drawable.flag); Animation an = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); flagImageView.startAnimation(an);
Image of page 110
Chapter 6 Summary We have learned what Android resources are. We have learned how to set simple resource values using Android Studio. We are now able to work with many different types of Android resources.
Image of page 111

Subscribe to view the full document.

Image of page 112
  • 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