Naming rules for Android resources

天大地大妈咪最大 提交于 2019-11-29 20:50:08

问题


where can I find the naming rules for Android resources? I found out thanks to compilation errors that I must use characters within [a-z0-9._], but I also have an error with an image named 401.png. When using it in my layout using

@drawable/401

I get the following compilation error:

invalid VariableDeclaratorId

I can't find these rules in the doc, and I'd like to know all of them before naming my files.

Thanks


回答1:


The rules are the same as for Java identifiers since each resource must have a corresponding ID field generated in the R.java file.




回答2:


Worth noting that: "File-based resource names must contain only lowercase a-z, 0-9, or underscore" characters. (quoted from compile error code).




回答3:


The number is not allowed as first char of resource also not any capital letter




回答4:


Your convention is correct, except that you can't start your file names with a number.




回答5:


Naming rules for resources are the same as for the variables, except the case-sensitivity. In your case, problem is the first character is number.




回答6:


This is Java rule, not Android-only rule. Name each element with a starting letter, and you'll be right.



来源:https://stackoverflow.com/questions/5949395/naming-rules-for-android-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!