What is "android:" prefix mean in android framework-res module

2.3k views Asked by At

I copy the this code from the styles.xml file in framework-res module

<style name="Theme">

    <item name="colorForeground">@android:color/bright_foreground_dark</item>
    <item name="colorForegroundInverse">@android:color/bright_foreground_dark_inverse</item>
    <item name="colorBackground">@android:color/background_dark</item>

.

<style name="Theme.Black">
    <item name="android:windowBackground">@android:color/black</item>
    <item name="android:colorBackground">@android:color/black</item>
</style>

As you see, they all have a attribute name which's value is windowBackground. But the formar has a android: and the latter doesn't. Is it really necessary to write a android: prefix in android framework?

2

There are 2 answers

2
Priya Kathir On BEST ANSWER

Found this to be an interesting question and tried exploring to find the answer.. This is what I found..

from: http://developer.android.com/guide/topics/resources/style-resource.html

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style
        name="style_name"
        parent="@[package:]style/style_to_inherit">
        <item
            name="[package:]style_property_name"
            >style_value</item>
    </style>
</resources>

item - Defines a single property for the style. Must be a child of a element. attributes: name Attribute resource. Required. The name of the style property to be defined, with a package prefix if necessary (for example android:textColor).

from: http://developer.android.com/guide/topics/manifest/manifest-intro.html

Resource values Some attributes have values that can be displayed to users — for example, a label and an icon for an activity. The values of these attributes should be localized and therefore set from a resource or theme. 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. For example: Values from a theme are expressed in a similar manner, but with an initial '?' rather than '@':

?[package:]type:name

And finally, I tried giving the attributes without android:, and it threw an exception, though it compiled successfully.

0
user370305 On

Accessing Platform Resources

Android contains a number of standard resources, such as styles, themes, and layouts. To access these resource, qualify your resource reference with the android package name. For example, Android provides a layout resource you can use for list items in a ListAdapter:

setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myarray));

In this example, simple_list_item_1 is a layout resource defined by the platform for items in a ListView. You can use this instead of creating your own layout for list items. (For more about using ListView, see the List View Tutorial.)