Why is it not possible to use capital letters in naming resources in android?

I recently started developing applications in android, and many tutorials said that we should not use capital letters when naming resources. Why is this? It is also not permitted to provide extensions such as .png and .xml. If I have two files button.png and button.xml, how does the application distinguish between two files?

+4
source share
2 answers
  • don't allow capital letter in resources just follow strict agreement

  • you cannot use two different types of resources with the same name in the same resource folder. for example, you have two resource files in drawable-hpdi. these are a.png and a.xml. When compiling, the compiler will show an error. But if you put a.png in drawable-hdpi and a.xml in drawable-mdpi, then it will not show any errors, since these two resources will be used in two completely different types of devices.

Another interesting thing I found is that if you use a.png and a.xml in the same folder, then the error will show that a.xml is duplicated. But if you use a.jpg and a.png in the same folder, then this will show that a.png is a duplicate. For this, we can guess that there is no file type priority. The compiler will perform a top-down search. since a.png is placed above a.xml, so the compiler will find a.png first, then when they find the xml file with the same name, they will show an error. and for the same reason, using a.jpg and a.png, a.png will show an error.

NB This answer is entirely based on my observation. I did not find any written documentation about this. So if someone proves my mistake with proof, then it will be highly appreciated

+3
source

Since part of the file name of the resource file will be used to create the resource identifier in the created Java file
gen/<your-package-path>/R.java
you cannot have the same resource file name with different extensions in the same directory.

Refer to using the source file name in the resource link for the Bitmap file

Since resource identifiers are Java variables, it is recommended that you follow the proposed Java convention for variables (see Wikipedia's Naming Conventions for Java ) to start their lowercase names.

+1
source

All Articles