Launcher2 Custom App shortcut icon

Source: Internet
Author: User

is still the Launcher2 code, this time the icon for the app to be displayed in Launcher2 to customize the icon.

The idea of this modification arises from the problem that is now encountered, that is, for a custom launcher, the interface icon style and the unity of the icon style is very important, so it is often used for launcher in the application icons are modified, But it's relatively easy to change the apk icon for one or two apps, but it's a bit grasp for large-scale revisions and it's pretty hard to manage. So I thought, now that I know launcher's method of loading and extracting icon_launcher in the application, it should also be possible to lidaitaojiang the half way to display our custom icon. So the following changes have been made.

The first is to copy the custom APK's launcher icon resource to the Launcher resource file, then start to enter the code section, skip the icon to extract part of the code parsing process, see Iconcache.java

    Is the flag of the custom icon Hzhang private static Boolean Ismyicon = false; ..... ... ..... .... ..... ..... ..... ..... ..... ..... ..... .........        Drawable Getfullresicon (activityinfo info) {Resources resources;        try {resources = mpackagemanager.getresourcesforapplication (Info.applicationinfo);        } catch (Packagemanager.namenotfoundexception e) {resources = null;            } if (resources = null) {int iconid = Setappicon (info.packagename);//info.geticonresource ();            if (iconid==0) {iconID = Info.geticonresource ();            Ismyicon = false;            }else {Ismyicon = true;            } if (iconID! = 0 &&!ismyicon) {return Getfullresicon (resources, iconID);            }else{resources = mcontext.getresources ();            Return Getfullresicon (resources, iconID);    }} return Getfullresdefaultactivityicon (); }
The above code is the definition of a flag bit, the role of this flag is to distinguish whether the application for my modified target, if I need to modify the application of the custom icon will be set to true, otherwise.

Also to explain the meaning of the above changes, the practice in the source code will be in each of the specified application APK resource file to extract the specified icon resources as the target image will be displayed, And if I need to customize then I will specify its resource resource path to the current Launcher resource resource, and from there to find my designated image as an icon instead. One of the Setappicon is to determine the specific need to extract the icon for which the application, is judged by PackageName, and return the image I specified in the Launcher resource ID, and specified to iconID.

Here is the Setappicon function code

private static int Setappicon (String packagename) {int iconID  = 0;if (Packagename.equalsignorecase ("com.my.xxx")) { Here is the application package name, the specific can be judged according to their own needs iconID =  r.drawable.app_icon_xxx;      Here is the picture resource}else if (packagename.equalsignorecase ("com.my.xxx")) {iconID = r.drawable.app_icon_xxx;} else if (packagename.equalsignorecase ("com.my.xxx")) {iconID = 0;} else if (packagename.equalsignorecase ("com.my.xxx")) {iconID = r.drawable.app_icon_xxx;} else if (packagename.equalsignorecase ("com.my.xxx")) {iconID =r.drawable.app_icon_xxx;} else if (packagename.equalsignorecase ("com.my.xxx")) {iconID = r.drawable.app_icon_xxx;} else if (packagename.equalsignorecase ("com.my.xxx")) {iconID = r.drawable.app_icon_xxx;} LOG.E ("Load app Icon", "app packagename is =" +packagename); return iconID;}
To the basic realization of the function here, you can see the basic is a simple operation, just add a bit of their own judgment in the source code added a part of their own picture resources.

It's not going to stick, it's simple. Basic can achieve all the icon customization, just need to know PackageName can, which also let me suddenly think of a lot of launcher is can change the theme, this is probably a simple launcher to change the theme of the method, If the subsequent unification of the background of the superscript should be more able to form a consistent style display.

Simply record.

Launcher2 Custom App shortcut icon

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.