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
Nowadays, many lead-based advertisers are no long...
Resource introduction of Orange Cat Super Short P...
Author: Yan Yongjun, Unit: China Mobile Smart Hom...
It turns out that some comedians are born because...
When you are all paying attention to the Redmi No...
With the advent of the data age, the previous ext...
2020 has been a year of ups and downs, and the sa...
Especially in recent times, Baidu has been acting...
LeTV and Xiaomi, two Internet companies that clai...
[[127970]] On the day Alibaba went public, Septem...
This article is reproduced from Leiphone.com. If ...
With the vigorous development of mobile communica...
The second day of the second lunar month every ye...
According to the standards of the authoritative m...
There is still no final investigation result on t...