Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@ in AndroidManifest.xml file

Tags:

android

xml

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?

like image 995
CW Holeman II Avatar asked Jun 19 '09 14:06

CW Holeman II


People also ask

What does AndroidManifest XML contain?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

Where is the AndroidManifest XML file?

xml file is created in the app's corresponding dist folder. The file is located at WorkspaceName>/temp/<AppName>/build/luaandroid/dist. The manifest file provides essential information about your app to the Android operating system, and Google Play store.

How do I open AndroidManifest XML?

Open your Android project and go to <AppProjectFolder>/app/src/main/. Open the app manifest file AndroidManifest. xml and add the following lines to the file as child elements of the <manifest> element. Note: You must include the QUERY_ALL_PACKAGES permission if your app targets Android 11 (API Level 30) or higher.

What is XML file in Android Studio?

XML stands for eXtensible Markup Language, which is a way of describing data using a text-based document. Because XML is extensible and very flexible, it's used for many different things, including defining the UI layout of Android apps.


2 Answers

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.

like image 171
CW Holeman II Avatar answered Oct 06 '22 15:10

CW Holeman II


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.

like image 42
allclaws Avatar answered Oct 06 '22 16:10

allclaws