25

What's the difference between ?android:attr/ and ?attr/ in an Android layout XML file?

Which one should we use in different situations?

0

2 Answers 2

20

From Difference between “?attr/” and “?android:attr/” in Android:

1. ?attr/

Defines and refers to the value of an attribute which you have defined on your own in your application.

2. ?android:attr/

It refers to the values of an attribute which are already available in Android built-in. More specifically, the ? implies an extra level of indirection. Think of it as de-referencing an attribute to fetch the resource it points to rather than referring to the attribute itself.

4
  • 5
    And do you by any chance know what's the difference between ?android:attr/ and ?android:? For example, there are colors ?android:attr/textColorPrimary and ?android:textColorPrimary. Both seem to work in the same way, but I didn't dig into the themes and code to check for differences. Official documentation on these seem to be quite scarce. Jun 7, 2019 at 9:16
  • 4
    developer.android.com/guide/topics/resources/… "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."
    – Allan
    Oct 18, 2019 at 1:33
  • There isn't any original contribution here. And it doesn't really answer the first question. And certainly not the second (which is probably the real one). What is the (essential) difference? What is the gist of it? Feb 17, 2023 at 22:27
  • Was it just the first search result that was pasted here? Feb 17, 2023 at 22:29
1

From Difference between “?attr/” and “?android:attr/” in Android:

?attr/

  • Defines and refers to the value of an attribute which you have defined on your own in your application.

?android:attr/

  • Refers to the values of an attribute which are already available in Android built-in.
1
  • There isn't any original contribution here. And it doesn't really answer the first question (based on the quote). And certainly not the second (which is probably the real one). What is the (essential) difference? What is the gist of it? Feb 17, 2023 at 22:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.