Tint(着色器)的兼容实现

咱们在作控件的时候能够使用tint这个属性给控件上色,这样在不少状况下能减小不一样色彩的资源色彩。在MD设计中,控件颜色随着主体改变也是一大要点,今天咱们就来看看如何使用它。segmentfault

使用步骤:1.创建一个控件;2.使用ViewCompat.setBackgroundTintListspa

      // 第一种实现
        ColorStateList cl = new ColorStateList(new int[][]{new int[0]}, new int[]{0xffffcc00});
        ViewCompat.setBackgroundTintList(pasteEt, cl);
        // 第二种实现
        ViewCompat.setBackgroundTintList(pasteEt, getResources().getColorStateList(R.color.red));

这里的colorstateList是什么东西呢,若是作过属性定制的同窗必定见过它,它就是一个color的xml文件,这里的color我用了最简单的定义方式:设计

<color name="red">#ff0000</color>

咱们有时候还会像selector同样定义不一样状态下的颜色,最终这些xml文件最终解析转为的东西就是colorStateList对象啦,这个对象保存了状态和不一样状态下的演示值。code

 

 

参考自:xml

http://segmentfault.com/a/1190000003038675?utm_source=Weibo&utm_medium=shareLink&utm_campaign=socialShare对象

http://stackoverflow.com/questions/27735890/lollipops-backgroundtint-has-no-effect-on-a-buttonblog

相关文章
相关标签/搜索