Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content


How To Access Resources In Android

In this Video tutorial we will learn what are the Resources and Assets in Android, and how we can use them both more effectively in our Android application.

So far, we have used resources many times within our application but now we will see what exactly that is. Our basic focus is on coding, but whatever content we are coding, we supply the content with the help of resources.

Bitmaps, colours, layout definitions, user interface strings, animation instructions, and many more are used with the help of resources.

Android Resources Organizing and Accessing

We can always externalize resources such as text strings, layouts, sounds, graphics or any other static data an Android Application may require from our application code so that it becomes easier to maintain and update them independently.

This helps us to alter code without modifying the resources.

Android automatically selects correct resources.



Resource Type


XML files that define a state list of colors. They are saved in res/color/ and accessed from the R.color class.


Images files like .png, .jpg, .gif or XML files are complied into bitmaps, state lists, shapes, animation drawable. They are saved in res/drawable/ and accessed from the R.drawable class.


XML files that define a user interface layout. They are saved in res/layout/ and accessed from the R.layout class.


XML files that define application menus, such as an options menu, context menu, or sub menu. They are saved in res/menu/ and accessed from the class.


Arbitary files to save in their raw form. You need to callResources.openRawResource() with the resource ID, which is R.raw .filename to open such raw files.


XML files that contains simple values, such as strings, integers, and colors. For example, here are some filename conventions for resources you can create in this directory.







Types of Resources

In Android there are two types of resources,

  1. Default resources
  2. Alternative resources

Default Resources

The resources that should be used to regardless the device configuration or when there are no alternative resources that match the available configuration.

Alternative resources

Resources which support specific device configuration. We will see alternative resources in depth further.

Android resources Organising and Accessing

We need to organise resources in our projects res/directory.

Using various sub directories that group resources by type and configuration.

Alternative Resources

Multiple sets of resources could be included in an application each customised for a different device configuration.

When the user runs the application Android automatically selects and loads the resources which best matches the device.

Your application should provide alternative resources to support specific device configuration.

Many times we can see that our Android application runs on different types of devices, like tablet smartphones etc.. So for that it requires different type of image size according to the screen resolution of particular device. So for that in Alternative resources we can store different images by the help of coding, and it will pick up the required image as per device supports.

Accessing Resources

As an Android application is compiled a 'R' class gets generated.

The R class defines all resource ID for our resources available in the res/directory.

We can provide a resource in application by referencing its resource ID.

Accessing resources in Code

For example, you can set an ImageView to use the res/drawable/myimage.png resource using setImageResource():

  • ImageView imageView=(ImageView) findViewById( view);



Consider the next example where res/values/strings.xml has following definition.

<?xml version=”1.0” encoding=”utf-8”?>


<string name=”welcome”>Welcome to LearnVern!</string>



Now you can set the text on a TextView object with ID msg using a resource ID as follows.


TextView msgTextView=(TextView) findViewById(;




Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere