Android “?colorPrimary” vs “?attr/colorPrimary”?

大憨熊 提交于 2019-12-07 09:07:31

问题


I can't find any information about the differences between:

android:textColor="?attr/colorPrimary"

vs

android:textColor="?colorPrimary"

I have read that "?attr" means attribute value specified in the current theme, but without "attr" it gives the same result (=color defined in my theme). It behaves similar with other attributes?

For example:

Does android:background="?attr/selectableItemBackground" equals android:background="?selectableItemBackground" ?

Here it's told that it differs.

Thanks very much.


回答1:


Ok, I have finally found in the docs:

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.

So, I deducted it's like this: the AppCompat library attributes are treated as custom attributes and as a result we point them by a question mark without "android" keyword. And "attr" is type of resource which is optional for both platform and custom attributes (from docs). Android documentation



来源:https://stackoverflow.com/questions/44391770/android-colorprimary-vs-attr-colorprimary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!