preface

  • The Android code specification is extensive, but one of the most useful and influential is the naming convention for Android code

  • However, many people tend to ignore the naming conventions of Android code, which leads to poor readability & maintainability of the code, resulting in reduced development & maintenance efficiency

  • Today, I will bring you a comprehensive and clear naming specification for Android code according to the Google Java Programming Specification & Google’s official Android coding specification. I hope you will enjoy it.

  • Ps: Recently, WE are preparing an activity called “Write Android with me”. We need the help of readers. I hope you can read the article and participate in it.I’d like to invite you to write Android with me


directory


1. Why standardize Android code naming?

  • Improve code readability
  • Enhance the maintainability of code

Because of the above two functions, the development efficiency & maintenance efficiency has been greatly improved.


2. What code (objects) does Android need to name?


3. Specific naming conventions

Below, I’ll take a closer look at naming conventions in Android code objects

Note: Since Android is primarily implemented in Java, the Android specification covers a portion of the Java specification

3.1 package

  • Basic rules: lowercase, consecutive words without spacing, anti-domain name method (divided into 4 levels, as shown below)

  • The level 4 package name will vary depending on the functionality. Below I list some common & level 4 feature pack names that need specification

3.2 class

  • Ground rules
    1. Type = noun/noun phrase;
    2. Form = hump formBig camel spelling(UpperCamelCase)

Capitalize the first letter of each word in the name, as in AndroidStudio

  • When you name a class, you attach additional naming conventions depending on the type of the class. The details are shown below.


3.3 variable

  • Ground rules
    1. Type = noun/noun phrase;
    2. Form = hump formLittle camel spelling(LowerCamelCase)

That is, the first letter of the name is lowercase and the first letter of each word is uppercase, as in androidStudioTool

  • When naming a variable, additional naming rules are added depending on the type of the variable. The details are shown below.

3.4 methods

  • Ground rules
    1. Type = verb/phrasal verb;
    2. Form = hump formLittle camel spelling(LowerCamelCase)

That is, the first letter of the name is lowercase and the first letter of each word is uppercase, as in androidStudioTool

  • When naming a method, additional naming rules are added according to the function of the method name. The details are shown below.

3.5 parameter name

  • Basic rule: in the hump formLittle camel spelling(LowerCamelCase)

That is, the first letter of the name is lowercase and the first letter of each word is uppercase, as in androidStudioTool

  • Additional naming rules: feature names, such asuserName

3.6 resources

  • Android resources include:

Below, I’ll take a closer look at the naming conventions for each Android resource

3.6.1 Layout file Resources

3.6.2 Image Resources

3.6.3 Parameter Value Resources

3.6.4 Animation Resources


3.7 additional

In addition to the above naming conventions, there are also some universal naming conventions in Android:

So far, the code naming conventions for Android are over


4. Appendix: List of commonly used abbreviations

  • Rule of abbreviations: Use only conventional abbreviations

Do not abbreviate words freely

  • The details are shown below.


5. To summarize

  • After reading this article, I’m sure you’ll take Android code naming seriously!

  • I’ll continue to dig into other code specifications in Android, but if you’re interested, stay tuned for Carson_Ho’s Android development notes

  • Ps: Recently, WE are preparing an activity called “Write Android with me”. We need the help of readers. I hope you can read the article and participate in it.I’d like to invite you to write Android with me


Please give me a thumbs up! Because your encouragement is the biggest power that I write!