什么是"android:" android-res模块中的前缀均值 [英] What is "android:" prefix mean in android framework-res module
问题描述
我从framework-res模块中的styles.xml文件复制此代码
<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>
如您所见,它们都有一个属性名,其值是windowBackground.但是形式有android:
,而后者没有.真的有必要在android框架中写一个android:
前缀吗?
发现这是一个有趣的问题,并尝试探索以找到答案.
来自: http://developer.android.com/guide/topic/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-为样式定义单个属性.必须是元素的子元素. 属性: 姓名 属性资源.必需的. 要定义的样式属性的名称,必要时带有包前缀(例如android:textColor).
来自: http://developer.android.com/guide/topic/manifest/manifest-intro.html
资源值 一些属性具有可以显示给用户的值,例如,活动的标签和图标.这些属性的值应本地化,因此应从资源或主题中进行设置.资源值以以下格式表示,
@[package:]type:name
,如果资源与应用程序位于同一软件包中,则可以省略软件包名称,其中type是资源的一种类型(例如字符串"或可绘制"),而name是标识特定资源的名称.例如: 主题的值以类似的方式表示,但以?"开头而不是"@":
?[package:]type:name
最后,我尝试在不使用android:的情况下给出属性,尽管编译成功,但它抛出了异常.
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?
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.
这篇关于什么是"android:" android-res模块中的前缀均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!