Android Styles: Difference between 'style=“@android:style/XYZ”' and 'style=“?android:attr/XYZ”'?

天大地大妈咪最大 提交于 2019-11-30 03:43:07
Barak

From another answer on SO (paraphrased here):

Using a question mark in front of an ID means that you want to access a style attribute that's defined in a style theme, rather than hardcoding the attribute.

Think of it as dereferencing a theme attribute to fetch the resource it points to rather than referring to the attribute itself.

Referencing Style Attributes

?android:attr/buttonBarButtonStyle or just ?android:buttonBarButtonStyle - (attr is optional)

<item name="buttonBarButtonStyle">@android:style/Widget.Button</item>

This internally dereferences to @android:style/Widget.Button which is defined within appcompat/res/values/themes.xml file.

(?android:) - always links to the value of the attribute from the current-theme applied. Thus allowing us to refer the android defined style only rather creating a new one and supplying a hard-coded value.

Google Doc says, "It uses the style that is defined by this attribute, in the current theme"

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