Android id naming convention: lower case with underscore vs. camel case

后端 未结 8 661
北荒
北荒 2020-11-30 21:26

I\'m currently programming an application for the Android. Now what I found out is that you cannot place resource objects, say, an image in the drawable folder and name it l

8条回答
  •  不知归路
    2020-11-30 22:13

    The device will not complain if you use camel-case id names. For my first application I wrote all the ids in camel-case because I think it appears better in the Java code that way, and it works just fine.

    I am slowly changing my mind on camel-case, though, because you end up with two different naming conventions - for example:

    // This must be undescored due to naming constrictions
    setContentView(R.layout.my_long_layout_name);
    
    // Now this looks a little out of place
    findViewById(R.id.myLongSpecificId);
    

    I, too, wonder about the standards here. Google is inconsistent in their examples; sometimes they use all lowercase, sometimes they insert underscores, and sometimes they use camel-case.

提交回复
热议问题