Difference between ?selectableItemBackground, ?android:selectableItemBackground and ?android:attr/selectableItemBackground in Android?

南楼画角 提交于 2019-12-03 08:00:51

问题


What is the difference between:

android:background="?selectableItemBackground"

android:background="?attr/selectableItemBackground"

android:background="?android:selectableItemBackground"

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

in Android?


回答1:


Here,

android:background="?selectableItemBackground"

is attribute reference from appCompat library so it is applied to older versions of android and doesn't need android prefix.

android:background="?android:selectableItemBackground"

is attribute provided by platform which may not support older android versions but only from version they are introduced.

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

Here use of attr applies to the attribute defined for current theme. i.e if you have your application theme set for light version then selectableItemBackground of light theme will be applied.

And you can define your own values which can be accessed without using android prefix.




回答2:


They all do the same work. The only difference is that android prefix is for android 3.0 and above and if you want to use the same attribute for android 2.3 and below you have to remove the android prefix. Thanks



来源:https://stackoverflow.com/questions/32819419/difference-between-selectableitembackground-androidselectableitembackground

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