Question mark on Android? And the use of the @ symbol (GO)

Source: Internet
Author: User

In general, we should use "@+id/" to define an ID, and then use @id to refer to an ID, but now I find that Apps/settings/res/layout/preferenc_progress.xml has a "@+android:id/ Title ", how to understand it?" How to use it?

Plus Android: indicates reference to Android. R.id inside the ID resource defined, if android.r.id inside does have the title of this ID resource, directly use it, if not, in the current application of the r.id to produce a title identifier
The ID is a basic property of the control, which does not mean that each control's ID is different, but the ID property of the control can be the same.
When all controls are loaded into memory, a control tree is formed, and when the control is found, only the first ID-matching control is returned, so if a control with the same ID on a page, such as the ListView item, looks for the control from its nearest parent node. That's how you hit it.

@ means referencing a resource, declaring that this is a resource reference-the subsequent text is a resource name in the form of a @[package:]type/name.
@android: String indicates the referenced system's (android.*) resource
@string means referencing an app's internal resources
For ID, you can use @+id to indicate the creation of an ID
? Represents a Reference property
“? "Referring to the Subject property, when you use this tag, the resource name you provide must be able to be found in the subject attribute because the resource tool thinks that the resource attribute is expected and you do not need to explicitly indicate its type (? Android:attr/android: Textdisabledcolor).

Use Theme 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 theme, rather than providing specific values.
As shown in the example, we use this feature in the layout resource to set the text color to one of the standard colors, which are defined in the basic system theme:

Java code
<?xml version= "1.0" encoding= "Utf-8"?>
<edittext id= "Text"
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent"
Android:textcolor= "? Android:textdisabledcolor"
android:text= "@string/hello_world"/>


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-because the resource tool knows the required property resource, so you do not need to explicitly declare the type (if the declaration, its form is? 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, here's the name syntax for that type:? [Namespace:]typpe/name and ' @ ' are also optional.

Question mark on Android? And the use of the @ symbol (GO)

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.