7

What's the difference between

android:color="@android:color/black"

and

style="?android:attr/borderlessButtonStyle" 

What's the difference between the @ and ? ?

This is one of those questions which is ungoogleable, or ogooglebar.

Chloe
  • 25,162
  • 40
  • 190
  • 357
  • From [Accessing Resources](http://developer.android.com/guide/topics/resources/accessing-resources.html): To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol `(@)`, use a question-mark `(?)`, and the resource type portion is optional. – devnull May 22 '13 at 05:40
  • This is not an ungoogleable.... :) – Pankaj Kumar May 22 '13 at 05:40
  • 1
    The url slug for this question is funny. – Andrew Barber May 22 '13 at 18:12
  • @PankajKumar It was until I asked it and Google stuck it near the [top](https://www.google.com/search?q=android+%40android+%3Fandroid&rlz=1C1CHFX_enUS526US526&aq=f&oq=android+%40&aqs=chrome.0.59j57j65l3j60.2289j0&sourceid=chrome&ie=UTF-8). Notice the duplicate question is not found. – Chloe May 22 '13 at 21:31

3 Answers3

9

@android:color/black

means you are referring to an color defined in the android namespace. This namespace is the namespace of the framework.

search black in this file: black color in framework

style="?android:attr/borderlessButtonStyle"

"?android:attr/borderlessButtonStyle" simply means "use the value defined by the attribute called borderlessButtonStyle in the namespace android." This attribute and its value are part of the Android framework, the "android" namespace.

borderlessButtonStyle in framework


Edited: from this Referencing Style Attributes

this link tell us:

For example, here's how you can reference an attribute to set the text color to match the "primary" text color of the system theme:

<EditText id="text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="?android:textColorSecondary"
    android:text="@string/hello_world" />
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
5

(from this answer and its comments)

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

Community
  • 1
  • 1
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
1

here Google has a document on it http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes

AAnkit
  • 27,299
  • 12
  • 60
  • 71