編寫(xiě):徐建祥(netpirate@gmail.com)
日期:2010/11/22
網(wǎng)址:http://www.anymobile.org
主要涉及兩個(gè)技術(shù)點(diǎn):
1、圖標(biāo)加灰色過(guò)濾;
2、android的圖片資源默認(rèn)是靜態(tài)的,單實(shí)例;如果兩個(gè)IM好友的頭像一樣,最簡(jiǎn)單的都是用的軟件自帶頭像,有一個(gè)在線,一個(gè)離線,直接改變頭像的灰度,則兩個(gè)用戶的頭像都會(huì)變灰或者在線,答案是:Drawable.mutate()。
代碼如下:
- Drawable mDrawable = context.getResources().getDrawable(R.drawable.face_icon);
- //Make this drawable mutable.
- //A mutable drawable is guaranteed to not share its state with any other drawable.
- mDrawable.mutate();
- ColorMatrix cm = new ColorMatrix();
- cm.setSaturation(0);
- ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);
- mDrawable.setColorFilter(cf);
OVER!