When we develop some applications or applications such as address book and social networking to add new function modules, we will consider adding the number of unread information to the corresponding icons or new function reminder icons, in this way, the goal of prompting can be achieved without occupying too much space.
Some people have asked me about the implementation of this kind of reminder in the MMS Analysis Section. I have summarized how to add this kind of reminder. There are several methods to achieve this:
1. Place textview or imageview in the corresponding layout.
2. Use canvas to draw on the bitmap of the original icon
3. It is convenient and flexible to add viewbadger, an open-source project.
The first method is to adjust the layout. The second method is not described here:
:
Here we use a custom function to retrieve images based on the resource icon ID. The Code is as follows:
/*** Obtain an image by ID * @ Param res * @ Param resid * @ return */private bitmap getresicon (Resources res, int resid) {drawable icon = res. getdrawable (resid); If (icon instanceof bitmapdrawable) {bitmapdrawable BD = (bitmapdrawable) icon; return BD. getbitmap () ;}else {return NULL ;}}
After obtaining the icon, you need to process it. You need to overwrite the number of the icon.
/*** Add the number in the upper-right corner of the given image * @ Param icon */private bitmap generatorcontactcounticon (Bitmap icon) {// initialize the canvas int iconsize = (INT) getresources (). getdimension (Android. r. dimen. app_icon_size); log. D (TAG, "the Icon size is" + iconsize); bitmap contacticon = bitmap. createbitmap (iconsize, iconsize, config. argb_8888); canvas = new canvas (contacticon); // copy the image paint iconpaint = new paint (); iconpaint. setdither (true); // anti-jitter iconpaint. setfilterbitmap (true); // used to filter bitmap. In this way, when you select drawable, rect src = new rect (0, 0, icon. getwidth (), icon. getheight (); rect DST = new rect (0, 0, iconsize, iconsize); canvas. drawbitmap (icon, SRC, DST, iconpaint); // enable anti-aliasing and use the text field of the device to paint countpaint = new paint (paint. anti_alias_flag | paint. dev_kern_text_flag); countpaint. setcolor (color. red); countpaint. settextsize (20f); countpaint. settypeface (typeface. default_bold); canvas. drawtext (string. valueof (count), iconSize-18, 25, countpaint); Return contacticon ;}
If any reprint is available, please declare the Source: Shi zhisha:
Http://blog.csdn.net/t12x3456