1 | initial version |
To implement a color filter using XML, you can use the following steps:
res/color
folder. For example, create color_filter.xml
with the following code:<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFAABBCC" />
</selector>
ImageView
and set its src
attribute:<ImageView
android:id="@+id/my_image_view"
android:src="@drawable/my_image" />
ImageView
using the android:tint
attribute and reference the color filter defined in color_filter.xml
:<ImageView
android:id="@+id/my_image_view"
android:src="@drawable/my_image"
android:tint="@color/color_filter" />
ImageView
with the color filter should be displayed.Note: You can also use the android:tintMode
attribute to specify the blending mode for the color filter. The default is src_in
which multiplies the source color with the tint color. Other modes include src_over
, dst_over
, multiply
, and screen
.