The implementation method of Android Launcher dynamic icon

Source: Internet
Author: User

In our use of Android system, often see a lot of icons online monogram Some numbers, such as the number of text messages, the number of messages and so on, it is curious, how this is achieved? And he will continue to change according to the actual situation, it is very magical, the default Android is not supported, then we have to speak slowly today, he is how to achieve.

Today we introduce two methods, one is to apply the shortcut, the second is to modify the Iauncher code to achieve the effect of dynamic icon, with other applications to achieve.

Found in the application, the common application can be, this is more magical, such as Pea pod, it will prompt you have several applications to upgrade, very curious, research, found that he has two application icons, we know that the application is really only one icon, and what is the other one? Yes, it's a shortcut to the application, he can create multiple or one, then we find the first way to implement it today.

The first is that it is very simple, we are flexible, we can use the desktop program to create a shortcut to achieve this, when our application changes in data change the time when the new shortcut is reinstalled, and it identifies some of our data, so that the true situation. Which icon we can put in advance in the program, about how to load shortcuts, you can see the previous reprint of an article http://blog.csdn.net/wx_962464/article/details/7457939.

The second way is to modify the launcher code, and then cooperate with other applications to achieve the effect of dynamic icon, before implementing it, the first to understand in launcher in the application installation, uninstall, update the time is how to do, here is about the introduction, in the application installation, update, uninstall time, There will be a broadcast, launcher in the launcherapplication to register the broadcast, in the Launchermodel processing received broadcast messages, the broadcast band parameter is an array of application packages, and then in a thread task to reload the update the corresponding contents of these packages , such as icon, text, etc., then I can simulate this effect, in application also register a broadcast, such as appchanged, and then in the Launchermodel processing, processing can simulate the application of the updated parts, a thread processing, The main thing is the icon in the Launcher Allapp interface, we found that launcher in the text and the icon in the Pagedviewicon this class generated, it is actually a textview, just rewritten, adding the relevant properties, The icon is in this method setcompounddrawableswithintrinsicbounds (null, New Fastbitmapdrawable (Micon), NULL, and NULL); This method is available in many of the view settings. He can set the control up and down around the icon, Launcher Allapp interface icon is set with TextView image, so here can be based on the application's package name and then make some special properties to judge, and then set the display of different icons, For the size of the icon we can use the Createiconbitmap method of the utilities class to fit the launcher icon. In other applications to send appchanged broadcast, and with the package name parameters, when the conditions specified in the Pagedviewicon, set the specified picture, you can achieve dynamic changes, this depends on the foreign program broadcast, so that the dynamic icon can be implemented.

Above just say, I recently do dynamic icon of the practice, and realized, I hope that the same needs can be referenced, no text interpretation, but the idea is such, what do not understand, said the bad please give me a message, I will reply.

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.