About Android:targetsdkversion

Source: Internet
Author: User

Recently encountered a problem, is originally a color icon, the result in the 5.x Device business status bar above notification icon color is black and white, and on the 4.x above is color.

Find this post on So, Http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop. The main idea is that this is the new behavior of 5.x (API 21), if the android:targetsdkversion in Androidmanfifext.xml is set to 21, then on the 5.x system, this behavior. If you must display color, like 4.x, set Android:targetsdkversion to the old API number, for example 20.

This paper studies the mechanism of the next targetsdkversion effective. For this example, you can see the implementation code for Basestatusbar:

if (Entry.targetsdk >= build.version_codes. LOLLIPOP) {    else  {    entry.icon.setColorFilter (null);}

He will determine whether to use black-and-white mode according to ENTRY.TARGETSDK.

The targetsdk here is in Android:targetsdkversion. If you look at the call relationship of this code, you will find that the value of ENTRY.TARGETSDK is through:

ApplicationInfo info = pmuser.getapplicationinfo (sbn.getpackagename (), 0= info.targetsdkversion;

Assignment, that is, the applicaitoninfo.targetsdkversion.

So if the app is running on a 5.x system (SDK version 21/22), if Targetsdkversion is specified as 21/22, then the black-and-white mode is applied, and if Targetsdkversion is specified as 20 or lower, This new primary color filter logic does not take effect, or the use of the original system behavior. So if we want to keep the application in the old system on the new system, it can be done by setting the property to the old API version.

If the targetsdkversion is set to 21 but runs on the old 4.x system (for example, API 19), it will not take effect because the actual SDK runtime does not handle this high-targetsdkversion code at all. And the SDK code is generally used >= a version number of the way to judge, so that write 21 and write 19 effect on 19 of the machine is exactly the same.

About Android:targetsdkversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.