IkramU

Notions on Software Development and Technology.

Resource Naming Convention for Android Library Projects

Use prefixes to avoid resource conflicts
To avoid resource conflicts for common resource IDs, consider using a prefix or other consistent naming scheme that is unique to the project (or is unique across all projects).

Add a prefix to the resource names or ids.
Here I use the prefix library.
Generally it is advisable to use the name (or abbreviation of the name) of your Library project.

  • Naming a drawable- library_image.png
  • Naming in layouts-
library_my_layout.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="utf-8"?>

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

  <ImageView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/library_imageView"
          android:src="@drawable/library_image"
          android:contentDescription="@string/library_image_description"/>
  <TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="@string/library_text"
          android:id="@+id/library_textView"/>

</LinearLayout>
  • Naming in string resource-
library_strings.xml
1
2
3
4
5
6
7
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="library_text">Text.
  </string>
  <string name="library_image_description">Image Description.
  </string>
</resources>

Comments