• Tint(着色器)的兼容实现


    我们在做控件的时候可以使用tint这个属性给控件上色,这样在很多情况下能减少不同色彩的资源色彩。在MD设计中,控件颜色随着主体改变也是一大要点,今天我们就来看看如何使用它。

    使用步骤:1.建立一个控件;2.使用ViewCompat.setBackgroundTintList

          // 第一种实现
            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对象啦,这个对象保存了状态和不同状态下的演示值。

    参考自:

    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-button

  • 相关阅读:
    面向对象 委托
    面向对象 继承 接口
    C# 面向对象 , 类与对象
    C# 知识点回顾
    SQL 数据库知识点回顾
    C# 10 总复习
    spring boot jpa 表关联查询分组 group by 去重
    钉钉新增考勤组 设置考勤规则
    elasticsearch 学习之父子关联查询 parent/child
    Elasticsearch 查询学习
  • 原文地址:https://www.cnblogs.com/tianzhijiexian/p/4699014.html
Copyright © 2020-2023  润新知