Android SharedPreferences Tutorial and Example

Vector Drawables in Android A Scalable Approach to Modern Icons

When you build an Android app, the small graphics tucked into buttons, navigation bars, and notification trays shape how users perceive your work. A pixelated icon on a six-inch display immediately cheapens an otherwise polished product. Vector drawables solve this by describing shapes in mathematical terms rather than fixed pixel grids. The file contains instructions: draw a line here, fill this region, curve around that point.

The idea has existed in graphics software for decades, but its arrival inside Android Studio reshaped daily workflows from Brisbane boardrooms to Perth home offices. Because XML-based vectors render crisply at any density, they remove the tedious chore of exporting every asset at mdpi, hdpi, xhdpi, xxhdpi, and xxxdpi. A single file scales from a smartwatch face to a wall-mounted kiosk without a second thought.

For Australian developers shipping apps to a market where over 80 percent of mobile users run Android, this is more than a stylistic choice. It is a practical lever for reducing APK size, surviving Play Store reviews, and keeping the visual identity consistent across the Samsung Galaxy A series popular in suburban Sydney and on the Pixel line sold through JB Hi-Fi.

The path to confident usage involves understanding XML structure, knowing when to combine vectors with animations, configuring backwards compatibility, and avoiding common performance traps. The sections that follow walk through each of these concerns with runnable snippets and pragmatic advice that fits inside a normal sprint cycle.

Understanding the Anatomy of a Vector Drawable File

A vector drawable is an XML file stored in the res/drawable folder of your project. It begins with a root <vector> element that declares viewport dimensions in density-independent pixels. Inside sit shape elements such as <path>, <group>, and <clip-path>, each describing a piece of the eventual image through SVG-style commands.

The real magic lies in the pathData attribute, where a compact string of letters and numbers tells the renderer where to move, draw, and close. An M 0,0 L 24,24 Z sequence draws a line from one corner to the opposite corner and closes the shape. Because Android caches the parsed object once, repeated draws remain cheap on the GPU.

Adelaide designers often export these paths directly from Figma using plugins, while developers writing by hand can quickly draft placeholders for prototyping. Either approach yields a file referenced exactly like a traditional PNG inside any ImageView, Button, or Toolbar.

Creating Your First Vector Drawable

Begin by right-clicking the drawable folder in Android Studio and choosing New, then Vector Asset. The Asset Studio window offers two routes: importing an existing SVG file, or building one from a Material icon shortcut. Selecting the latter opens a searchable gallery organised by category, from accessibility symbols to social logos.

Once chosen, you adjust the resource name, tint colour, and viewport size. The generated XML resembles the snippet below.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="#1976D2"
        android:pathData="M12,2L4,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-8,-3z"/>
</vector>

Drop the file into your layout with android:src="@drawable/ic_security" and toggle the device frame selector to preview at multiple densities. Sydney-based designers often compare icons against the typical chrome of Samsung One UI to confirm the silhouette reads clearly even at 18dp.

Comparing Vector Drawables With Raster Alternatives

Raster images such as PNG and WebP store fixed pixel data. That makes them suited for photographs but poor candidates for simple monochromatic shapes. Every density bucket requires its own file, inflating the APK by hundreds of kilobytes before Android App Bundle splitting kicks in.

Vector drawables ship one file that adapts to every density and to unusual screen sizes like the foldables gaining traction in Australian carrier stores. They cannot replicate every kind of artwork, however. Richly detailed illustrations still demand raster formats.

The table below summarises the trade-offs most relevant to everyday Android work.

Feature Vector Drawable (XML) PNG / WebP (Raster)
Scaling behaviour Lossless at any density Fixed to source resolution
File count per icon One XML file Multiple density buckets
Typical file size 1–6 KB 5–80 KB per density
Best suited for Icons, logos, simple shapes Photos, complex illustrations
Animation support Native via AnimatedVector Requires frame sequences
Backwards compatibility Needs AppCompat below API 21 Supported everywhere
Tint and recolour support Easy via tint and theme Requires separate asset

Many production apps shown at Sydney Build conferences mix both approaches, using vectors for UI chrome and rasters for richer imagery.

Animating Vector Drawables for Engaging Interfaces

Beyond static rendering, vector drawables integrate with the AnimatedVectorDrawable class to support property animations on individual paths. Define a target XML wrapping the original vector, then list <objectAnimator> entries that interpolate pathData, fillColor, or other attributes between keyframes.

A common pattern in Melbourne fintech apps is a success tick that morphs from a circle into a checkmark after a transfer confirms. The animation looks fluid because it operates on vector paths rather than swapping whole images, keeping GPU usage steady on mid-range Xiaomi devices circulating across Australia.

Pairing this with a MotionLayout transition lets you build entire interactive flows without touching a frame animation file, a useful shortcut when deadlines meet long weekends spent watching the AFL.

Supporting Older Devices Through AppCompat

Android introduced vector drawables natively in API level 21, otherwise known as Lollipop. Apps that need to run on KitKat and earlier must enable AppCompat's vector support inside the build.gradle file. Adding vectorDrawables.useSupportLibrary = true instructs the build pipeline to generate PNG fallbacks during release builds.

This backward shield works transparently for most developers, but two caveats catch newcomers. Not every attribute animates correctly through the support library, and Lint sometimes flags complex pathData as too costly to render. Both issues resolve with a tidy compatibility check listed in Android Studio's Inspection menu.

Australian studios serving enterprise clients often still target API level 19 because of integration partners. Setting the compatibility flag saves hours of confusion when submitting to review boards accustomed to legacy handsets.

Optimising Performance and Avoiding Common Mistakes

Although vectors are lightweight, misuse introduces subtle regressions. A pathData string with hundreds of commands can stress older GPUs, particularly on devices routed through regional networks with higher latency such as the long NBN tails in outback Queensland. Keeping each icon under roughly 800 path segments remains a sensible rule of thumb for budget phones.

Tint handling deserves care as well. Applying android:tint on the view rather than modifying the underlying drawable allows runtime theme changes without rebuilding the drawable tree. This proves handy when a dark mode toggle arrives mid-session, as it often does in apps following Material 3 expressive design conventions.

Audit unused drawables periodically through Android Studio's Refactor > Remove Unused Resources menu. Trimming stranded XML files keeps APK weight down and ensures the Play Store listing shows a respectable size, which matters when competing with hundreds of similar Australian utilities on the storefront.

Practical Recommendations for Working With Vector Drawables

  • Export icons from Figma or Illustrator as SVG with stroke-to-path conversion enabled, then import through the Asset Studio to preserve visual fidelity.
  • Reserve vectors for monochrome glyphs and simple logos, falling back to WebP only when gradients or photographic detail are essential.
  • Wrap interactive vectors inside AnimatedVectorDrawable where motion clarifies state, such as loading, success, or error feedback.
  • Enable vectorDrawables.useSupportLibrary in module-level build.gradle whenever minSdk drops below 21 to keep older Android versions covered.
  • Lint the drawable folder monthly and remove unused XML resources to keep the APK small and review-ready for the Play Console.