What's the difference between @android: and ?android: [duplicate]

血红的双手。 提交于 2019-11-30 07:01:17

问题


What's the difference between

android:color="@android:color/black"

and

style="?android:attr/borderlessButtonStyle" 

What's the difference between the @ and ? ?

This is one of those questions which is ungoogleable, or ogooglebar.


回答1:


(from this answer and its comments)

Prefixing the ID with a question mark indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute, as explained in Referencing Style Attributes.

More specifically, the ? implies an extra level of indirection. Think of it as dereferencing a theme attribute to fetch the resource it points to rather than referring to the attribute itself. You see this with ?android:attr/foo




回答2:


@android:color/black

means you are referring to an color defined in the android namespace. This namespace is the namespace of the framework.

search black in this file: black color in framework

style="?android:attr/borderlessButtonStyle"

"?android:attr/borderlessButtonStyle" simply means "use the value defined by the attribute called borderlessButtonStyle in the namespace android." This attribute and its value are part of the Android framework, the "android" namespace.

borderlessButtonStyle in framework


Edited: from this Referencing Style Attributes

this link tell us:

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



回答3:


here Google has a document on it http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes



来源:https://stackoverflow.com/questions/16684131/whats-the-difference-between-android-and-android

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