This is a question for Android developers but it is not a programming-related question as it affects nothing but the developer.
What conventions are the most commonly used when naming various resources like colors, drawables and strings and etc?
I have no doubts naming my layouts activity_main or layout_secondary. However, I have always doubts when naming resources mentioned previously. I never know whether I should name these resources after their use or the content. For example:
- Color:
dark_bluevstext_highlighted - Drawable:
blue_gradientvstop_bar_background - String:
welcome_to_appvsfirst_time_prompt
Is there any community-created resource for good practice?
Naming is pretty much personal preference. The name is perfect as long as the name indicates what the functionality of the defined thing is. Also you and any other developer using these definitions should know how what the names mean and which definition to choose. Quite easy if you are consistent with names throughout the project.
For example
dark_blueis obviously a blue color whiletext_highlightedis the color of highlighted text. The name you should use depends on what you need: if you want to classify colors by their name take the first, if you like to abstract from the actual color take the second. For general layouts usingtext_highlightedwill often make more sense since the actual color does not matter and the functionality (text highlight vs text regular etc.) is more important. In this example choosing betweentext_highlightedandtext_regularis a lot more obvious than choosing betweencolor_light_blueandcolor_dark_bluealthough they could refer to the same color. The name can help prevent errors.Android uses prefixes for names in [
android.R.drawable](http://developer.android.com/reference/android/R.drawable.html) for example:
btn_for button graphicsic_for icon graphicsic_menu_for menu iconsic_dialog_for dialog iconsstat_for status iconsThe schema is certainly not perfect but the advantage of using prefixes that start with the most generic classification is that you can use code completion to search for specific items step by step. So
color_blue_darkcould be better thandark_blue_color, at least if you consider the color classification more important than the dark / light classification. The same applies tofirst_time_prompt. If you have a lot ofprompts it would make sense to name themprompt_first_time,promt_other_time, … If they can be classified by an activity for example that could be used as super category:mainactivity_prompt_*,secondactivity_prompt_*so you know where they belong to.