问题描述
我在看的蜂窝图库样张code(这里一>),我跑过以下code,而试图在自己的应用程序添加行动项目:
I am looking at the Honeycomb Gallery sample code (here) and I ran across the following code while trying to add action items in my own app:
<item android:id="@+id/camera"
android:title="Camera"
android:icon="?attr/menuIconCamera"
android:showAsAction="ifRoom" />
在?ATTR
是扔我一个循环。是否有人可以解释一下这个是干什么的?这是如何与一个绘制?我似乎无法找到谷歌什么好消息。也就是有上市或属性的画廊,我们可以使用的图标,而不是仅仅 menuIconCamera
?
The ?attr
is throwing me for a loop. Can someone please explain what this is doing? How is this related to a drawable? I can't seem to find any good information on Google. Also is there a listing or gallery of attributes we can use for icons instead of just menuIconCamera
?
感谢
编辑:我做了一些更多的环顾四周,发现attrs.xml看起来是这样的:
I did some more looking around and found that attrs.xml looks like this:
<resources>
<declare-styleable name="AppTheme">
<attr name="listDragShadowBackground" format="reference" />
<attr name="menuIconCamera" format="reference" />
<attr name="menuIconToggle" format="reference" />
<attr name="menuIconShare" format="reference" />
</declare-styleable>
不幸的是,只是使它更加混乱了我。这是什么做的?
Unfortunately that just makes it even more confusing for me. What is this doing?
推荐答案
在?ATTR / menuIconCamera
值表示从图标 menuIconCamera
当前主题的属性将被使用。
The ?attr/menuIconCamera
value means that an icon from menuIconCamera
attribute of the current theme will be used.
必须有指定给 menuIconCamera
A绘制属性在的themes.xml
文件的地方。如果是两个主题与此属性不同的值,则实际的图标,将取决于目前正在使用的一个主题。
There must be a drawable assigned to the menuIconCamera
attribute somewhere in the themes.xml
file. If there're two themes with different values of this attribute then actual icon will depend on a theme which is currently used.
在 attrs.xml
文件用于定义自定义属性。如果没有这个定义编译器会把未知属性为错误。
The attrs.xml
file is used to define custom attributes. Without this definition compiler will treat unknown attributes as erroneous.
这篇关于有人可以解释的ATTR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!