6

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"
    />

From page 44:

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

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

3 Answers 3

8

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.

6

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.