随笔
今天在学习时,设计背景色,发现提醒我不要用background属性
所以我在这说一下background与backgroundTint的区别:
//这是backgroundTint的源码
<!-- Tint to apply to the background. -->
<attr name="backgroundTint" format="color" />
//这是background的源码
<!-- A drawable to use as the background. This can be either a reference
to a full drawable resource (such as a PNG image, 9-patch,
XML state list description, etc), or a solid color such as "#ff000000"
(black). -->
<attr name="background" format="reference|color" />
- 其实这个注释已经说了backgroundTint是应用到背景上的色彩
- 而background是一个可绘制的背景,可以是一个完全可绘制资源的引用(例如图片、可调整大小位图9-patch、XML状态列表描述、etc),或者是纯色如黑色。
format格式的区别就是backgroundTint只能用颜色,而background有引用和颜色。
自然就是,如果你只是要给背景上纯色的话,建议用backgroundTint,如果你要用背景图片的话,就用background,可以分别提高对应的执行效率!!!