我们在开发应用程序引用资源时,一般会使用@drawable/**这种方式,偶尔也会碰到使用?attr/来引用的,其区别在于:
1.@style/引用的资源是固定的,是直接引用资源目录下的实际资源
?attr/代表主题属性,引用的资源,是可以跟随不同主题来改变的。因此?引用的资源必须在theme中声明
2.自定义?attr/**:
// 1.首先在attrs.xml中声明属性,format为reference
<declare-styleable name="AppAttr">
<item name="myColor">@color/white</item>
</declare-styleable>
// 2.主题中引用
<style name="AppTheme">
<item name="myColor">@color/white</color>
</style>
// 3.使用
android:background="?attr/myColor"