What is the difference between background, backgroundTint, backgroundTintMode attributes in xroid layout?

While working with android XML design, I came across the backgroundTint attribute. I don’t understand why.

And what is backgroundTintMode ??

+53
android android-layout
Sep 09 '15 at 4:39 on
source share
4 answers

I tested various combinations of android:background , android:backgroundTint and android:backgroundTintMode .

android:backgroundTint applies a color filter to the android:background resource when used with android:backgroundTintMode .

Here are the results:

Tint check

Here is the code if you want to experiment further:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_main"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:textSize="45sp" android:background="#37AEE4" android:text="Background" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:textSize="45sp" android:backgroundTint="#FEFBDE" android:text="Background tint" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:textSize="45sp" android:background="#37AEE4" android:backgroundTint="#FEFBDE" android:text="Both together" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:textSize="45sp" android:background="#37AEE4" android:backgroundTint="#FEFBDE" android:backgroundTintMode="multiply" android:text="With tint mode" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:textSize="45sp" android:text="Without any" /> </LinearLayout> 
+43
Jun 28 '16 at 15:31
source share

The backgroundTint attribute helps you add a hue to the background. You can specify the color value for it in the form - "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

On the other hand, backgroundTintMode will help you apply the background shade. It should have constant values ​​like src_over, src_in, src_atop, etc.

Refer to this for a clear idea of ​​the constant values ​​you can use. A backgroundTint attribute search and description along with various attributes will be available.

+7
Sep 09 '15 at 5:16
source share

BackgroundTint works like a color filter.

Febde as a shade

37AEE4 as background

Try to see the difference in the value / background of the comment and check the output when both options are set.

+4
Sep 09 '15 at 5:25
source share

android: backgroundTintMode

Blend mode used to apply the background color.

android: backgroundTint

Tint to apply to the background. There must be a color value in the form #rgb , #argb , #rrggbb or #aarrggbb .

It can also be a link to a resource (in the form "@ [package:] type: name") or a theme attribute (in the form "? [Package:] [type:] name") containing a value of this type.

+2
Sep 09 '15 at 5:46
source share



All Articles