1

What's the purpose of having a separate ?-qualifier for style-attributes ? Why not use the @-qualifier ?

    <Button
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:drawable/ic_media_play" />  
Andy
  • 488
  • 4
  • 13
  • possible duplicate of [Question mark (?) in XML attributes for Android](http://stackoverflow.com/questions/2733907/question-mark-in-xml-attributes-for-android) – Knossos Apr 08 '15 at 10:00

1 Answers1

1

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

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. For instance:

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

Here, the android:textColor attribute specifies the name of a style attribute in the current theme. Android now uses the value applied to the android:textColorSecondary style attribute as the value for android:textColor in this widget. Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type (which would be ?android:attr/textColorSecondary)—you can exclude the attr type.

Source: HERE

Mohammad Arman
  • 7,020
  • 2
  • 36
  • 50
  • 1
    thx for this precise explanation. This topic (styles and themes) is very important I think, but not well documented by most authors (even the online- documentation on http://developer.android.com/ is not thorough). I also think, that some authors confuse the term "style". To me a style is a named collection of attribute-value pairs. However some refer to this as a style-attribute or an attribute-value and confusion is perfect. – Andy Apr 08 '15 at 12:09