Can someone explain the attr?

attr means
android attributes
found item attr more than one time
attr xml android
android attributes formats
r attr
android r attr
android declare-styleable

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" />

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?

Thanks

Edit: 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?

The ?attr/menuIconCamera value means that an icon from menuIconCamera attribute of the current theme will be used.

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.

The attrs.xml file is used to define custom attributes. Without this definition compiler will treat unknown attributes as erroneous.

jQuery attr() Method, also has its very own attributes which can be used with ? The ?attr/menuIconCamera value means that an icon from menuIconCamera attribute of the current theme will be used. 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.

The ?attr: syntax is used for accessing attributes of current theme. See referencing style attributes.

What does ?attr/ mean on Android?, , someone might be labeled beautiful, charming, funny, or intelligent. However, in ATTR amyloidosis, the protein becomes unstable, breaks apart, and deposits in the heart and/or the nerves. There are two types of ATTR Amyloidosis: Hereditary (familial) ATTR amyloidosis. In this form, there is a change (mutation) in the DNA that is inherited and can be passed from one generation to the next.

I know this post is very old, but I feel the following explanation will help beginners understand it easily.

So in layman's terms,

someAttribute="?attr/attributeName" means -

set the value of someAttribute to whatever is the value of attributeName in current theme

A common example occurs in styling a Toolbar

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary_color</item>
       //some more stuff here
</style>
<!-- custom toolbar style -->
<style name="myToolbar" parent="Widget.AppCompat.Toolbar">
      <item name="android:background">?attr/colorPrimary</item>
     //some code here
</style>

Here value of android:background will be set to @color/primary_color because ?attr/colorPrimary refers to @color/primary_color in the current theme (AppTheme)

When to Use the Attribute (ATTR) Function, I found this to be useful, but I can see how non-developers might get lost in this formula. My next step to crack this code was to reach out to my  Can someone explain me the difference between a cost function and the gradient descent equation in logistic regression?

My English is not good, sorry. But I know this question

android:icon="?attr/menuIconCamera" want use

attrs.xml

<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>
</resources>

styles.xml

<style name="AppTheme.Light" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/ActionBar.Light</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="listDragShadowBackground">@android:color/background_light</item>
        <item name="menuIconCamera">@drawable/ic_menu_camera_holo_light</item> //this....
        <item name="menuIconToggle">@drawable/ic_menu_toggle_holo_light</item>
        <item name="menuIconShare">@drawable/ic_menu_share_holo_light</item>
    </style>

use @drawable/ic_menu_camera_holo_light

Examples of Attributes, An attribute is defined as a quality or characteristic of a person, place, or thing. Read on to enjoy For example, someone might be labeled beautiful, charming, funny, or intelligent. These are all What are their attributes? Will these labels  You can experiment more and figure out things as you go. Eg. you can build high Int fighter and its not going to be automatically worthless right at the start. It's certainly an interesting approach, which should open up builds a lot and allow a lot more creativity to the player.

This is for refering style Attributes. see R.attr

?[<package_name>:][<resource_type>/]<resource_name>

Referencing style attributes

ATTR(), Typing ATTR at a DOS prompt will explain how to use ATTR.COM. For more I long ago lost track of the number of microcomputers at MEC. While I have  An attribute is defined as a quality or characteristic of a person, place, or thing. Read on to enjoy some examples of attributes and suss out the difference between attributes and traits.

Newsletter, Can someone explain me the difference between an attribute and property with jQuery. I have guess, I'm not sure if is ok: Attribute: Is something  Attribute definition is - a quality, character, or characteristic ascribed to someone or something. How to use attribute in a sentence. Did You Know? Synonym Discussion of attribute.

Difference between "attr()" and "prop()", am I right, The other binding I used in this example was attr, which sets the value of an You can see this in the label element in the listing, where I added a couple of span An alternative is to create custom bindings, which I explain in Chapter 4. class Person attr_accessor :name end person = Person.new person.name = "Dennis" person.name # => "Dennis" Works the same way! And guess what: the instance variable @name in our person object will be set just like when we did it manually, so you can use it in other methods.

Pro JavaScript for Web Apps, The attr() method sets or returns attributes and values of the selected elements. When this method is used to set attribute values, it sets one or more attribute/​value Examples might be simplified to improve reading and basic understanding. in order from your attribute list. As for what each does: Health is how much damage you can withstand. More health means you can take more damage. Not much else to say on that. Ki is how much energy meter (the bar below your health) you have. Ki is used for specials and ultimates and is also used for Saiyans to become Super Saiyan.

Comments
  • you are exactly right, <item name="menuIconCamera">@drawable/ic_menu_camera_holo_light</item>, Thank you so much. I see that ic_menu_camera_holo_light is a local drawable. Does 3.x not have public icons built in like 2.x had?
  • I don't think it's somehow connected to Android version. This is just a way of making attributes dependent on a chosen theme.
  • The supplied link was very, very helpful. Thanks!
  • Very helpful, but you should still post the main parts of that link.
  • This was the most helpful part of the linked article: 'A style attribute resource allows you to reference the value of an attribute in the currently-applied theme. Referencing a style attribute allows you to customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hard-coded value. Referencing a style attribute essentially says, "use the style that is defined by this attribute, in the current theme."'
  • One thing that doesn't seem to be documented anywhere is that '<package_name>' is the full package name of whatever declared the resource. More specically, it's not an XML namespace prefix, even though the syntax might suggest that. For example to refer to an attr declared by the appcompat library, use android.support.v7.appcompat:.