Skip to content

Common Default Resources Folders in Android

In an Android project, the res/ (resources) folder contains all the non-code assets like UI layouts, images, themes, colors, and strings. These resources help in creating a scalable, multilingual, and responsive UI.


πŸ“‚ res/ Directory Overview

app/src/main/res/
│── drawable/
│── mipmap/
│── layout/
│── values/
│── raw/
│── xml/
│── font/
│── animator/
│── anim/
│── menu/
│── color/

Each folder has a specific purpose. Let’s discuss them in detail.


πŸ”Ή 1. drawable/ (Images & Graphics) 🎨

Contains images, shape drawables, and vector assets used in UI elements.

πŸ“Œ Types of Drawables:

File TypeDescriptionExample File
Bitmap ImagesStores PNG, JPG, WEBP imageslogo.png, background.jpg
Vector DrawablesXML-based scalable imagesic_launcher.xml
Shape DrawablesXML files for gradients, borders, buttonsrounded_button.xml
State DrawablesXML for button states (pressed, focused)button_selector.xml

πŸ“Œ Example: Button Shape Drawable (button_background.xml)

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF6200EE"/>
<corners android:radius="8dp"/>
</shape>

πŸ”Ή Best Practice: Use Vector Drawables instead of PNGs to save storage.


πŸ”Ή 2. mipmap/ (App Icons) 🏞️

  • Stores app launcher icons in different resolutions.
  • Used instead of drawable/ for better scalability and performance.
  • Common sizes:CopyEditmipmap-hdpi/ mipmap-mdpi/ mipmap-xhdpi/ mipmap-xxhdpi/ mipmap-xxxhdpi/

πŸ“Œ Example: Setting App Icon in AndroidManifest.xml

<application
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round">
</application>

πŸ”Ή Best Practice: Use adaptive icons for consistency across devices.


πŸ”Ή 3. layout/ (UI Layout Files) πŸ“„

  • Contains XML files that define the user interface (UI) structure.
  • Used for activities, fragments, RecyclerView items, dialogs, etc.

πŸ“Œ Example File Structure:

res/layout/
│── activity_main.xml
│── fragment_dashboard.xml
│── item_list.xml

πŸ“Œ Example: Activity Layout (activity_main.xml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/textTitle"
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

πŸ”Ή Best Practice: Use ConstraintLayout for flexible and responsive UI design.


πŸ”Ή 4. values/ (App-wide Constants) πŸ—οΈ

Contains XML files storing reusable values like colors, dimensions, styles, and strings.

πŸ“Œ Common Files in values/ Directory:

FilePurpose
strings.xmlStores text for localization.
colors.xmlDefines app color palette.
dimens.xmlStores dimensions (margins, text sizes).
styles.xmlStores themes & styles for UI consistency.

πŸ“Œ Example: strings.xml

<resources>
<string name="app_name">MyApp</string>
<string name="welcome_message">Welcome to MyApp!</string>
</resources>

πŸ“Œ Example: colors.xml

<resources>
<color name="primaryColor">#6200EE</color>
<color name="background">#FFFFFF</color>
</resources>

πŸ”Ή Best Practice: Never hardcode text and colors in XML or Java/Kotlin. Use values/ instead.


πŸ”Ή 5. raw/ (Media & Other Files) 🎡

  • Stores raw assets like MP3, MP4, JSON, text files.
  • Used for audio, video, configuration files, etc.

πŸ“Œ Example: Play Audio from raw/ Folder

MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.sound_file);
mediaPlayer.start();

πŸ”Ή Best Practice: Use res/raw/ for media files instead of assets/.


πŸ”Ή 6. xml/ (App Configurations) βš™οΈ

  • Contains configuration files like permissions, preferences, and network security settings.

πŸ“Œ Common Files:

FilePurpose
network_security_config.xmlDefines security settings (HTTPS rules).
preferences.xmlStores shared preferences (settings).

πŸ“Œ Example: network_security_config.xml

<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">example.com</domain>
</domain-config>
</network-security-config>

πŸ”Ή Best Practice: Use xml/ for app-wide settings instead of hardcoding.


πŸ”Ή 7. font/ (Custom Fonts) πŸ†Ž

  • Stores custom fonts for app text styling.
  • Supports TTF and OTF font files.

πŸ“Œ Example: Adding Custom Font (font/roboto.ttf)

<TextView
android:text="Hello"
android:fontFamily="@font/roboto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

πŸ”Ή Best Practice: Store all fonts in res/font/ for easy access.


πŸ”Ή 8. anim/ & animator/ (Animations) 🎬

  • Stores animation XML files for UI effects.

πŸ“Œ Example: Fade In Animation (res/anim/fade_in.xml)

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>

πŸ”Ή Best Practice: Use animator/ for property animations and anim/ for view animations.


πŸ”Ή 9. menu/ (Navigation Menus) πŸ”

  • Defines toolbar menus, bottom navigation, and contextual menus.

πŸ“Œ Example: Toolbar Menu (menu_main.xml)

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_settings"
android:title="Settings"
android:icon="@drawable/ic_settings"
android:showAsAction="always"/>
</menu>

πŸ”Ή Best Practice: Use menu/ for toolbar and bottom navigation menus.


πŸš€ Summary: Why Use Default Resource Folders?

βœ… Better organization of assets.
βœ… Easier localization & theme management.
βœ… Efficient memory & performance optimization.
βœ… Improves code maintainability and scalability.