11

I find there are two case in some demo codes, What is the difference between ?android:attr/textAppearanceMedium and ?android:textAppearanceMedium ? Thanks!

Case 1

<resources>
    <style name="myTextAppearance">
        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    </style>  

Case 2

<resources>
    <style name="myTextAppearance">
        <item name="android:textAppearance">?android:textAppearanceMedium</item>
    </style>  
</resources>

3 Answers 3

12

According to Android Developer API Guide - Accessing Resources - Referencing style attributes, the resource type is optional if the system resource tool can figure out the correct resource type. So they are referring to the same value.

5

I think they both do the same, that is refer to a theme attribute.

The DOCS say...

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

The [type:] being optional.

More explanation in the following links...

need explanation for android layout syntax

References to Theme Attributes

1

There are no one difference between ?android:attr/textAppearanceMedium and ?android:textAppearanceMedium.

You can use each of them, as you wish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.