How to Add Vector Assets in Android Studio?
Last Updated :
18 Apr, 2021
Vector Assets in Android Studio helps to add material icons and import Scalable Vector Graphics and Adobe Photoshop Document files into your project as vector drawable resources.
How Vector Asset is different from Image Asset?
Image Asset Studio helps us create different types of icons with different densities and shows us exactly where they'll be placed in our project. It includes tools for adjusting our icons and adding backdrops, all while displaying the result in a preview pane, so they appear exactly as we intended. Vector Asset Studio helps to add a vector graphic to our project as an XML file that describes the image.
Problem using PNG’s
The PNG format can surely handle high-resolution photos. PNG format is a lossless web format. Hence, file sizes tend to get very large. If we want to work with photos on the web, we should always try to continue with JPEG. And the main issue for printing a .png file is its inherent color profile. The colors of the images may be a little dull since the printer has to interpret a different color language. Each PNG asset which we use is a certain density specific. Therefore, we have to deal with different versions of the same image for different screen sizes. To get rid of such problems we use vector assets.
Bitmap vs Vector
There are the following differences between Bitmap and Vector:
- Bitmap uses pixels while vector uses geometric shapes.
- Bitmap images are comparatively larger than vector images.
- Bitmap type is suitable for photographs while vector type is suitable for logos, clip arts, and icons.
- Resizing the images affects the resolution in the case of Bitmap images which resolution is preserved in Vector images.
- Bitmap images can be edited using Adobe photograph while Vector images can be edited using Adobe Illustrator.
Benefits of Vector Assets
Image scalability is the major advantage of using the vector drawable. The same file can be resized for different screen sizes without loss of image quality which results in smaller APK files and less developer maintenance. We can also use vector images for animation.
How do vector assets render?
The vector assets are first compiled to binary format at compile time and then at runtime. Next, the application is needed to load this up, generates a model object from binary code, and perform some canvas operations to draw the individual paths to the screen.
Vector Formats
There are the following vector file formats:
- .ai: abbreviation for Adobe Illustrator which is commonly used to print media and digital graphics.
- .eps: abbreviation of Encapsulated PostScript which doesn’t support transparency in the way .ai format does.
- .pdf: abbreviation of Portable Document Format which is built for the exchange of documents across platforms.
- .svg: The Scalable Vector Graphics format is based on XML. It’s useful for the web, where it can be indexed, searched, and scripted.
Step by Step Implementation
Step 1: Right-click on drawable > New > Vector Asset
After clicking on Vector Asset a new dialog box is opened that is shown below.
Step 2: Click on Clip Art and Search for the Icons and click ok button
Step 3: Change the color of the icon
Icon color can be changed either by directly adding color code or by adjusting the color using brightness and then click on choose button.
Step 4: Click Next
Step 5: Now Click on Finish Button
Step 6: Icon is created in the drawable folder as shown in the image
Similar Reads
How to Convert a Vector to Bitmap in Android? A vector is a set of points, lines, and colors associated with any image object defined inside an XML file. All these associated attributes are compiled in real-time to develop an image object. Simply, a vector is a coded representation of an image object. Bitmap, also known as bitmap index or bit a
3 min read
How to Create a Wallpaper App in Android Studio? Almost all Android devices are having a wallpaper set on their home screen. For setting this wallpaper to the screen many Android devices provides a Wallpaper Application where we can browse different types of wallpapers based on various categories. In this article we will look at, building a simila
15+ min read
How to Add Image to Drawable Folder in Android Studio? The resource folder is the most important folder because it contains all the non-code sources like images, XML layouts, UI strings for the android application. In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the
3 min read
How to Add Audio Files to Android App in Android Studio? The audio file format is a file format for saving digital audio data on a computer system and all are aware of audio files. So in this article, we are going to discuss how can we add audio files to the android app. There are three major groups of audio file formats: Format Name Description Examples
3 min read
How to Use SVG Vector Drawables in Android? SVG stands for Scalable Vector Graphics. It is used for rendering two-dimensional images on the internet. SVG is used for high-quality images that can be scaled to any size. we can use SVG files in android too. SVG can be used for icons, for creating images for creating beautiful UI. In this post, w
2 min read