What is Tint When I first came across the word Tint, I actually didn’t quite understand its meaning, and I wasn’t clear on the purpose of Google inventing it. It is usually used in conjunction with Background, but now that we already have Background, why do we still need Tint? Tint translates to coloring. Coloring, what color? It is related to the background, of course, the background color. When I develop a client and use the appcompat-v7 package, in order to achieve the effect of Material Design, we will set several colors in the theme, such as primaryColor, colorControlNormal, colorControlActived, etc., and some components we use, such as EditText, will automatically change to the background color we want. In the case of only one background image, this approach greatly reduces the size of our apk package. The way to do this is to tint our background image with a color. Looking at the upcoming SegmentFault for Android 2.7, the issue feature, the color of this EditText is the same as our main color. It uses the TintManager class to color its background (green).
Okay, now that we understand the meaning of tint, let’s take a look at how all this is achieved. Look at the core code, there are only a few lines
Normally, our mode is usually SRC_IN. If you want to know more about this attribute, here is the portal: http://blog.csdn.net/t12x3456/article/details/10432935 (Chinese) Because API Level 21 and before did not support background tint settings in XML, the ViewCompat.setBackgroundTintList method and ViewCompat.setBackgroundTintMode were provided to manually change the color that needs to be tinted, but the related View was required to inherit the TintableBackgroundView interface. Let's take a look at how the source code is implemented. Let's take AppCompatEditText as an example:
The above is compatible with API 21 and below. For example, if I want to implement Tint support for a custom component, I only need to inherit it and add some code. The code is as follows (almost universal):
|
<<: Ten days after the Android vulnerability broke out, it changed Google and Samsung
>>: Remember! Do not perform time-consuming operations in the UI main thread
In news about animals, there is often a very humo...
As 2019 is coming to an end, I believe many peopl...
What is the most valuable thing on the Internet? ...
Produced by: Science Popularization China Author:...
Mohe, Heilongjiang Extremely cold weather continu...
Biden talks infrastructure Background made in Chi...
At around 4:50 am on March 18, a natural landslid...
This article mainly introduces whether Douyin can...
You must have noticed that when you buy eggs, the...
How to increase activation volume ? Similar quest...
Although Douyin has launched an anti-addiction sy...
As the saying goes, a year's plan starts with...
When operators take advantage of users’ anxiety, ...
Chapter 1: Introduction to Weibo Fantong Basics 1...
On March 27, well-known digital whistleblower @Jo...