Android 有时候制作按下的效果挺麻烦的,得放色值不同的两张图,这个就比较尴尬了,明明是相同的资源。现在Android Material Design 中提供了一个东西:Tint,一张矢量图是能适配所有的颜色。
如下,相同的两个图,使用 tint 改变颜色:
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:src="@mipmap/ic_launcher" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:src="@mipmap/ic_launcher" android:tint="#FFF" />其中btn_begin为png图片,而btn_begin_pressed则是使用此图进行tint着色后的xml文件.
android:tint: 设置的是颜色
android:tintMode:设置的是类型(src_in,src_over,src_atop,add,screen,multiply)
各个属性效果如图:
tinMode
然后不管在xml布局中android:background,还是java代码setBackgroundResource,都可以直接使用成品背景图了
为了实现 Material Design的效果,使用的主题里的颜色配置比如 primaryColor,colorControlNormal,colorControlActived什么的会让 EditText 自动适配背景颜色,
其实现方式就是使用了 tint ,如下图:
随便举个栗子
先不用在意那个 TextInputLayout,看背景色,对就是那条线./抠鼻~
然后我们不想用这个颜色怎么办捏?
对于那条线可以直接设置:
android:backgroundTint="@color/颜色"额,那个光标也想改了??需要新建一个 cursor_shape.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <size android:width="1dp" /> <solid android:color="@color/颜色" /> </shape>然后就可以设置:
android:textCursorDrawable="@drawable/cursor_shape"谈谈Android Material Design 中的Tint(着色)
说到了 tint 着色,不得不提一下Android5.0加入的取色器:Palette,可以根据Bitmap显示出来的东西提取颜色,然后到处 set,达到背景或者 toolBar 和图片达到和谐,看看效果:
MD大法好
来自:http://www.jianshu.com/p/9c5baee9da4c
