Reputation: 81791
If you are developing Android application, you will encounter such a id naming in xml files of view and layouts :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game" />
<item android:id="@+id/quit"
android:icon="@drawable/ic_quit"
android:title="@string/quit" />
</menu>
and I am really wondering why such naming is applied to ids. It is because of Linux? What kinda meaning this naming --@+id/...
--has?
When I am looking at android:icon
attribute I can interpret that it means ic_new_game
is located under drawable folder and @
means "located at" or I just assume that.
But naming id attributes are kinda different because they also have +
sign. Can somebody help me understand this convention?
Thanks.
Upvotes: 5
Views: 561
Reputation: 39605
It is just a naming convention defined by the Android developers I guess. The +
is only used when you want to define a new Id for something. Otherwise you just reference is like @id/...
.
The @drawable/...
and @string/...
just represent a reference to some resources. Where drawable references get created automatically for .png
, .jpg
, .gif
and .xml
files residing in one of your drawable
directories. The filename of your file will be the identifier.
The string references get created if there is a XML file containing string tags like this one <string name="some_name">Some Name</string>
. The identifier for strings will be what you define as the name argument. In this example it would be @string/some_name
.
Same applies for your layouts. You will be able to access them through @layout/...
.
As far as I know it has nothing to do with Linux or at least I don't know anything in Linux like that.
An interesting read about this is Accessing Resources on the developer site.
Upvotes: 5