Summary of XML basics in Android development

Source: Internet
Author: User

The most basic file structure for an Android app

1.res Storage resource File

2.src storing Java source files

3.androidmanifest.xml

In
this middle, Java is responsible for the processing of logic, while the layout information of interface design is responsible for XML.

There are usually two ways to design a user interface: procedural and declarative. Android app Development supports both of these. But in fact, Google recommends using the declarative XML language as much as possible, because it is more concise and more efficient.

The XML is described below.

XML (extensible Markup Language)is an HTML-like markup language whose markup is not XML-predefined, but you define it yourself.

XML can be used to describe data, with a focus on "what the data is".

The following is the syntax structure of XML found online:



Then there are some fixed usages in XML, which take the arrogant Weather learning corner :

An [email protected] represents a reference resource

1. Reference a custom resource.

Format: @[package:]type/name

android:text= "@string/hello"

2. Refer to System resources.

Format: @android: Type/name

Android:textcolor= "@android: color/opaque_red"

Note: in fact @android: Type/name is a subclass of @[package:]type/name

Two [email protected]* represents a non-public resource referencing the system.

Format: @*android:type/name

System resource definitions are divided between public and non-public. The declaration of public is in:

<sdk_path>\platforms\android-8\data\res\values\public.xml

@*android:type/name: can invoke all system-defined resources

@android: Type/name: A resource that can only invoke the Publi property.

Note: Resources that are not declared in Public.xml are not recommended by Google.

Three.? Delegate reference topic Properties

Another resource value allows you to reference the value of a property in the current theme. This property value can only be used in style resources and XML attributes, and it allows you to change the appearance of UI elements by changing them to the standard changes provided by the current topic, rather than providing specific values. For example:

Android:textcolor= "? Android:textdisabledcolor"

Note that this is very similar to resource references, except that we use a "?" Prefix instead of "@". When you use this tag, you provide the name of the property resource, which will be looked up in the subject, so you do not need to display the declaration of that type (if the declaration is in the form of Android:attr/android:textdisabledcolor). In addition to using the identifier of this resource to query the values in the topic instead of the original resource, its naming syntax is the same as "@":? [Namespace:]type/name, this type is optional.]

four [email protected]+ represents a resource in the creation or reference.

Format: @+type/name

Meaning: "+" means a record is added to the inner class named type in R.java. as the meaning of "@+id/button" is in the ID of the R.java file, this static inner class adds a constant named button. The constant is the identifier for the resource. If the identifier (including system resources) already exists, it indicates that the identifier is referenced. The most common use is in defining the resource ID, for example:

@+id/Resource ID name Create a new resource ID

@id/resource ID name to apply an existing defined resource ID, including the system ID

@android: ID/Resource IDs reference the system ID, which is equivalent to the @id/resource ID name

Android:id= "@+id/selectdlg"

Android:id= "@android: Id/text1"

Android:id= "@id/button3"


Summary of XML basics in Android development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.