Kermit Kermit - 1 year ago 75
Android Question

what is the real difference between "android:" and "attr"?

When I attemp to use some resource in activity_main.xml like that


I found some thing i can't understand.I know the "android:" means system level attribute when an XML parser reads the document, "attr" means the attribute in my theme(right?), but why some attribute should add the package name "android:",though there is a same attribute? such as i can define attribute in my styles.xml like this

<item name="colorPrimaryDark">@color/purple</item>

but i also can define attribute like

<item name="android:colorPrimaryDark">@color/purple</item>

My English is very bad,so mybe i haven't explain what i want to figure out.

Answer Source

(from this answer )

Prefixing the ID with a question mark indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute, as explained in Referencing Style Attributes.

More specifically, the ? implies an extra level of indirection. Think of it as dereferencing a theme attribute to fetch the resource it points to rather than referring to the attribute itself. You see this with ?android:attr/foo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download