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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With