views:

321

answers:

4

From the O'Reilly book "Android Application Development " by Rick Rogers, John Lombardo, Zigurd Mednieks & Blake Meike:

page 23:

 <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

page 44:

 <application android:icon="@drawable/icon2">

What is the meaning of the "@" in each of the above fragments?

+6  A: 

I tend to think of it as an abbreviation that has to do with where resources are located, so:

In a normal setup, it would be something like:

@drawable/icon = /PROJECT_ROOT/res/drawable/icon.png

@string/hello = /PROJECT_ROOT/res/values/strings.xml (an element named "hello")

This seems like extra trouble, but it actually works pretty well. It also makes support for internationalization and different screen sizes pretty easy. You just declare additional resources files for different country codes and layouts and Android picks the best match for you.

This document about internationalization here might make it more clear why they decided to do it that way.

allclaws
A: 

It's the type of resource: http://developer.android.com/guide/topics/manifest/manifest-intro.html

Andrew Sledge
+6  A: 

In this case:

android:layout_width="fill_parent"

the value for the attribute, android:layout_width, is specified directly inside the quotes, fill_parent. In the other case:

android:text="@string/hello"

the value for the attribute, android:text="@string/hello", is specified elsewhere. This is indicated by the @ at the beginning of the string. In this example it is @string/hello. The value is in a resource.

From the "Resource values" section in The AndroidManifest.xml File from the Android Developers site. Found from link in allclaws answer.

Resource values are expressed in the following format,

@[package:]type:name

where the package name can be omitted if the resource is in the same package as the application, type is a type of resource — such as "string" or "drawable" — and name is the name that identifies the specific resource.

C.W.Holeman II
A: 

I've heard that the @ symbol is short for the word "attribute"

Pete Herbert Penito
All of the values in the example are for attributes but just one has the @.
C.W.Holeman II