Drawable Resources
Mobile Application
Model
Android resources
• All Android applications are composed of two things:
1. Functionality (code instructions)
• Functionality is the code that determines how your application behaves.
• This includes any algorithms that make the application run.
2. Data (resources)
• Resources include text strings, styles and themes, dimensions, images and
icons, audio files, videos, and other data used by the application.
What are the Android resources?
• Resources are the additional files and static content that your code uses,
such as
• bitmaps
• layout definitions
• user interface strings
• animation instructions
• and more.
• Always externalize app resources such as images and strings from your
code, so that you can maintain them independently.
What is layout resource in Android?
• A layout resource defines the architecture for the UI in an
Activity or a component of a UI.
file location: res/layout/filename.xml
• The filename is used as the resource ID. compiled resource
datatype: Resource pointer to a View (or subclass) resource
resource reference:
In Java: R.layout.filename
What is @+ ID in Android layout?
• @+id is used for defining a resource where as @id is used
for referring the resources which is already defined.
• android:id=”@+id/unique _key” creates a new entry in
• R. java. android: layout _below=”@id/unique _key” refer to
the entry which is already defined in R.
Drawable Resources
• A drawable resource is a general concept for a graphic
that can be drawn to the screen and that you can retrieve
• with APIs such as getDrawable(int) or
• apply to another XML resource
• with attributes such as android:drawable and android:icon.
• There are several types of drawables available in Android
Drawable Resources - examples
• res/drawable/filename.xml
• In Java: R.drawable.filename
• In XML: @[package:]drawable/filename
android:src="@[package:]drawable/drawable_resource"
// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.my_image);
i.setContentDescription(getResources().getString(R.string.my_image_desc));
Drawable Resources - examples
Resources res = context.getResources();
Drawable myImage = ResourcesCompat.getDrawable(res, R.drawable.my_image, null);
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"
android:contentDescription="@string/my_image_desc" />
<!-- res/drawable/expand_collapse.xml -->
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/image_expand"/>
<item android:drawable="@drawable/image_collapse"/>
</transition>
Where is the drawable folder?
• In Android Studio inside the res folder, one can find the
• drawable folder
• layout folder
• mipmap folder
• values folder, etc.
• Among them, the drawable folder contains the different types
of images used for the development of the application.
Drawable Resources – Android Studio
Drawable
Resources
XML in
Android
Studio
Drawable Resources – Android Studio
Drawable
Resources
XML in
Android
Studio
Drawable Resources – Android Studio
Drawable
Resources
XML in
Android
Studio
Questions
Thank You