Android中的?selectableItemBackground,?android:selectableItemBackground和?android:attr/selectableItemBackground之间的区别?

fra*_*ssb 17 android android-xml

有什么区别:

android:background="?selectableItemBackground"

android:background="?attr/selectableItemBackground"

android:background="?android:selectableItemBackground"

android:background="?android:attr/selectableItemBackground" 
Run Code Online (Sandbox Code Playgroud)

在Android?

小智 33

这里,

android:background="?selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

是来自appCompat库的属性引用,因此它应用于旧版本的android并且不需要android前缀.

android:background="?android:selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

是由平台提供的属性,可能不支持较旧的Android版本,但仅限于它们被引入的版本.

android:background="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

这里使用attr适用于为当前主题定义的属性.即如果您的应用程序主题设置为轻型版本,则将应用轻型主题的selectableItemBackground.

您可以定义自己的值,无需使用android前缀即可访问.

  • 谢谢,@subhash。您能提供文档的链接吗? (2认同)