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
[[127717]] 1. Global shipments of Android phones ...
Flowers smile to birds, frogs sing to willows, wa...
Different from fission, referral refers to the be...
Since the 2021 adult education entrance examinati...
Not long ago, a shocking news came out from the C...
The video, created by Terence Tuhinanshu, shows a...
Copywriting has always been a very popular job : ...
If you are troubled by the unstable taste of the ...
“This is a social APP that will subvert WeChat!” ...
I think many people thought when they were young ...
As a person who has been working in the market fo...
Apple's iPhone sales for the quarter will be m...
Nowadays, many offline businesses are trying out ...
Whether in our daily life or work, dealing with p...
From the transformation to the new media matrix h...