@in AndroidManifest.xml file

From O'Reilly's book, Android Application Development, by Rick Rogers, John Lombardo, Sigurd Mednieks, and Blake Mike, p. 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 @ in each of the above snippets?

+6
android xml
source share
3 answers

In this case:

 android:layout_width="fill_parent" 

the value of the android:layout_width specified directly inside the fill_parent quotes. Otherwise:

 android:text="@string/hello" 

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

From the Resource Values ​​section to the AndroidManifest.xml file from the Android Developers site. Found from the link in allclaws .

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 an application, the type is the type of the resource - for example, "string" or "drawable" - and the name is the name that identifies the specific resource.

+7
source share

I tend to think of it as a reduction that is related to the location of resources, therefore:

In normal setup, it will be something like this:

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

@ string / hello = / PROJECT_ROOT / res / values ​​/ strings.xml (element called hello)

This seems like an additional problem, but it actually works very well. It also facilitates internationalization and various screen sizes. You simply declare additional resource files for different country codes and layouts, and Android chooses the best match for you.

This internationalization document here may make it clearer why they decided to do it this way.

+6
source share
0
source share

All Articles